Script to Copy Files (of a particular type) from 1 location to another?


Recommended Posts

Can someone help me write a quick script to copy files from 1 location to another?

I have files in this folder structure:

C:\Other Files\Misc\<Load of individual folders with different names>\<Mixture of different file types>

I want to copy all the .doc files from the <Mixture of different file types> folder to the following location:

E:\Other Files\Misc

Can someone help me with a script that will do it for me? Thanks in advance!

Link to comment
Share on other sites

Open Notepad

Type

copy c:\otherfiels\misc\thefolderyouwanttocopyfrom\*.doc(orotherfiletype) e:\otherfiles\misc

Save as a mycopyscript.bat

You may have to edit the TXT off the end as it may save as mycopyscript.bat.txt

Move it to the desktop for easy access

Link to comment
Share on other sites

Open Notepad

Type

copy c:\otherfiels\misc\thefolderyouwanttocopyfrom\*.doc(orotherfiletype) e:\otherfiles\misc

Save as a mycopyscript.bat

You may have to edit the TXT off the end as it may save as mycopyscript.bat.txt

Move it to the desktop for easy access

lol! Give me some credit! That's simple. But I have about 50 odd folders in the Misc folder, I don't want to start typing 50 odd snippets of code in the batch file! It'll probably be faster to do it manually! I wanted to know if it's possible to write a script that will scan the randomly named folders. I.e. What variable do I need to specify for "thefolderyouwanttocopyfrom" part!

Link to comment
Share on other sites

Just dumping them all in one location? Have your script change to the source directory then try something like this:

for /r %x in (*.doc) do copy "%x" "D:\Destination\Directory"[/CODE]

That'll recursively scan every directory from where its called from.  Remember that this'll just dump everything found into one destination, it won't preserve the directory structure.
If you want to keep the directory structure, could use RoboCopy instead, included with current versions of Windows, oldies I think need a resource kit.  Similar to above, but it'll create directories as needed in the destination instead of just dumping all in one location. Another example:
[code]robocopy "C:\Source\Directory" "D:\Destination\Directory" *.doc /s

  • Like 2
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.