|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (1 bit)
Join Date: May 2011
Posts: 1
|
Help with Batch file!
Hey guys. I need a little help on a batch file I need to write for a new job. This is a huge oportunity for me to impress my new employers, so any help is greatly appreciated!
I've never quite done anything like this before. So ignore my ignorance. But here goes, I'll try to explain what the code needs to do. The batch file needs to open a series of files. find a specific file type. and copy that file type into a new folder. Specifically the folders branch downward like this.. ::will be used for comments:: ::starting from my Z drive, the numbers that follow are folders within each other that lead to place where we are looking for our (.dat) file:: z:\ , V10 , 2011, 00, 00, 00 ::up to this point, its just a single folder (00) within a single folder within a single folder within the z drive:: ::but then inside the last 00 folder opens alot of folders counting from 00, 01, 02, 03, 04.. 99. and inside of everyone of these 99 folders is a .dat file that I need to pull out, and copy into a new folder somewhere.:: -THIS IS THE HARD PART I really hope that wasn't to hard to follow. So far, I have this: cd z:\V10\2011\00\00\00 pause which brings me to the folder containing 99 other folders. Now I feel like I need to write a for loop or something to search in each individual folder for my (.dat) Thanks guys! any help is appreciated! |
|
|
|
|
|
#2 | |
|
Ride 'em Cowboy
Join Date: Dec 1999
Location: Dallas, Tx
Posts: 9,109
|
Right off the bat you stated:
Quote:
__________________
Stand Up 2 Cancer - SU2C |
|
|
|
|
|
|
#3 |
|
Member (10 bit)
Join Date: Jan 2010
Location: N. Calif.
Posts: 529
|
You want to use a FOR loop. Open a command prompt and type in "help for" (no quotes).
Something like this should be close to what you want. copy_dat.bat @echo off z: cd \V10\2011\00\00\00 for /D %%a in (*.*) do for %%b in (%%a\*.dat) do copy %%b \tmp This should loop thru each folder in the \V10\2011\00\00\00 folder and copy all dat files within those folders to the tmp folder at the root of Z:. You should change the copy to location to suite your needs. The folder you copy to needs to already exist. This doesn't restrict itself to only those folders named 00, 01, 02, etc... but looks at all folders. If there are other folders with different names that need to be excluded then this won't work for you but should give you an idea on how to proceed. Also, if the dat files don't have unique names they will overwrite each other. If there are files that will get overwritten you'll probably get prompted with a msg like "...Overwrite? Y/N" BTW, the line "cd z:\V10\2011\00\00\00" in your post will only work if you are already on the z: drive, the cd command cannot change to a different drive. If you need to change drives you need to specify the drive on a separate line then do the cd.
__________________
Been using, building, repairing and programming computers for nearly 30 years now. Last edited by strollin; 05-25-2011 at 08:23 AM. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|