Go Back   PCMech Forums > Help & Discussion > Software Discussion & Support

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 05-25-2011, 06:03 AM   #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!
flat_beer is offline   Reply With Quote
Old 05-25-2011, 07:23 AM   #2
Ride 'em Cowboy
 
EzyStvy's Avatar
 
Join Date: Dec 1999
Location: Dallas, Tx
Posts: 9,109
Right off the bat you stated:

Quote:
The batch file needs to open a series of files. find a specific file type. and copy that file type into a new folder.
"Open" a series of files means - launch and application(s)... Do you Really need to do that? Or did you mean "Look inside" a bunch of folders for a certain file type?
__________________
Stand Up 2 Cancer - SU2C
EzyStvy is offline   Reply With Quote
Old 05-25-2011, 08:14 AM   #3
Member (10 bit)
 
strollin's Avatar
 
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.
strollin is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:05 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2