Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file to copy files ONLY out of sub folders 1

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi.. I have a folder structure like this:

-HOMEFOLDER
--FOLDER1
---FILE1.tif
---FILE2.tif
---FILE3.tif
---FILE4.tif
---FILE5.tif
--FOLDER2
---FILE1.tif
---FILE2.tif
---FILE3.tif

etc. Is there a copy command or batch file i can run that will: copy all file*.tif files out of the HOMEFOLDER\SUBFOLDERS and into another folder?

Thanks!

Brian
 
Do you want it to create the subfolders in the destination folder, or only copy the files without the subfolder?

if the first option try:

Code:
xcopy source destination /s

Example:

xcopy C:\homefolder d:\otherfolder /s

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Worked perfect, thanks! BTW, what if I wanted to 'move' the images instead of 'copy'. Any idea on that?
 
I tried the xcopy c:\homefolder d:\otherfolder /s and thought it worked, but it did not.

Vacunita - I am looking to copy the files only without the sub folders.

If I have 100 files in 10 sub folders, I'd like to end up with all 100 files in one folder.
 
Have you tried

Code:
rd folder_name

This will remove the entire folder and subfolders and all files within.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ooooohh o.k i get it:
You'll have to cycel through each folder to copy/move the fles inside.

My expertise of for loops in batch files is somewhat limited, but i'm sure someone here can come up with a decent batch file for the job.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Can I use the FOR command? I'm trying some variables, but can't get it to work. Thought I might provoke a thought that would help someone come up with an idea.
 
Ok this isnt using a batch file but if you want to you can do this with windows and winzip pretty easily.
Do a search for all tiff files in the folders concerned. Zip up the search results and then just extract them in the destination folder. You can even keep the same folder structure if you tell winzip to remember it.
You could also use this to move the images as you wanted - after you have zipped the files - just delete the search results.
 
Thanks Teckystuff. That option works, but I'm looking for a way to automate it through a batch file

BTW, same works by running a windows search for *.* in your folder and then copying or cutting your results.

 
BTW, same works by running a windows search for *.* in your folder and then copying or cutting your results.

Faced with the same issue recently (I ran a utility to "sort" my MP3 files, and it sorted them by artist, making a folder for each one, *THEN* it made a folder for each song, and placed the file inside of that.. .ARRGH!)

Well, I did a search on that drive for *.mp3, then in the search window, CTRL-A (select all), then edit --> Cut, then went to the destination folder, edit --> Paste to put them all back in one folder for a re-sort.



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
this should work, not sure if there is a quicker way though but here goes remembering to place the batch file in homefolder
------------------------------------------------
cd folder1
copy/move *.tif
cd ..
cd folder2
copy/move *.tif
------------------------------------------------
repeat for each folder



Laters, phat, headshape
 
I found a way, that works, for your needs.

Code:
FOR /R [red]drive:\sourcefolder\[/red] %%G IN ([red]*.txt[/red]) DO copy %%G [red]drive:\targetfolder\[/red]

Put this in a bat file, call it whatever you want, and replace the red parts with the appropriate parameters.

It will cycle through the subfolders of [red]sourcefolder[/red] and execute the DO part on each file in the current subfolder.

so you can then change DO copy %%G ... with DEL %%G to acomplish the second part of your question which was to delete every file there.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita! I think we are on the right track. I'm getting a message that says %%G was unexpected at this time. Any idea what that means?
 
The error means that the parameter %%G is not supposed to be where you have it.

Can I see how the FOR looks with your substitutions?




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top