Jump to content



Photo

  • Please log in to reply
3 replies to this topic

#1 Zoom7000

Zoom7000

    The Ankle Breaker

  • Joined: 12-November 03
  • Location: London, UK
  • OS: Windows 8.1/OS X 10.10
  • Phone: iPhone 6 Plus

Posted 26 May 2013 - 16:12

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!


#2 helpifIcan

helpifIcan

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 19-September 10
  • Location: Northern Illinois

Posted 26 May 2013 - 17:36

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

#3 OP Zoom7000

Zoom7000

    The Ankle Breaker

  • Joined: 12-November 03
  • Location: London, UK
  • OS: Windows 8.1/OS X 10.10
  • Phone: iPhone 6 Plus

Posted 26 May 2013 - 19:51

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!

#4 Max Norris

Max Norris

    Neowinian Senior

  • Tech Issues Solved: 22
  • Joined: 20-February 11
  • OS: Windows 2012R2, 7, BSD Unix
  • Phone: HTC One (Work) Lumia 1020 (Home)

Posted 26 May 2013 - 20:18

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"

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:

robocopy "C:\Source\Directory" "D:\Destination\Directory" *.doc /s