Go Back   PCMech Forums > Windows Support > Windows Legacy Support (XP and earlier)

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-06-2006, 05:29 PM   #1
Member (5 bit)
 
Join Date: Feb 2006
Location: Memphis TN
Posts: 16
Send a message via MSN to johnny5
Batch file help

I hope someone can help with this...

I have about 5000 + files in a folder every morning. Each file is for a different customer but unless you go into every one of them, there is no way to tell who it is for. I know how to use the FINDSTR or FIND command to search all of these files for the customer's number however - customers may have 10 or more files on any given day. I have a scrip that finds the string (customer's number) and output's ONLY the file name in which it exists to a separate outfile. Is there a way to then rename the files in that are listed in the outfile or is there another easy method for getting them renamed?

Any input on this is much appreciated!

Thanks
Johnny

Last edited by johnny5; 12-06-2006 at 05:50 PM.
johnny5 is offline   Reply With Quote
Old 12-06-2006, 06:43 PM   #2
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Add this line to top of your batch script:
Code:
REM create a variable, filedate which is the current date in MM-DD-YYYY format
for /F "tokens=2,3,4 delims=/ " %%a in ('date /t') do set filedate=%%a-%%b-%%c
Then when you are copying the existing files, just prepend the file date variable.
For example:
Code:
xcopy "c:\some path\some file.doc" "c:\copy to path\%filedate%_some file.doc"
Obviously replace the path and file name with the value from the list you built.
This would insure each file is named differently from one day to the next.
faulkner132 is offline   Reply With Quote
Old 12-07-2006, 09:33 AM   #3
Member (5 bit)
 
Join Date: Feb 2006
Location: Memphis TN
Posts: 16
Send a message via MSN to johnny5
Ahhh - I may not have been clear on what I am trying to do. Im not trying to rename the file that has the list of filenames. I need to rename all of the filenames that are IN the list.

For example...

I have 5000 files named as such:
pedigree1
pedigree2
pedigree3
pedigree4
pedigree5
- thru pedigree5000
etc. etc.
(there are over 5000 of these files)
Each file is for a different customer - but there are 40 + of these files that belong to one customer in particular. The only way to know which customer it's for is by opening each file individually and that dog won't hunt!

So I run the findstr command to search inside all of these files for the customer's number - which gives me a list of all the files that are for that customer.
I get:
pedigree11
pedigree15
pedigree16
pedigree19
pedigree27
pedigree28
pedigree29
pedigree33
pedigree40
pedigree42
pedigree46
pedigree47
pedigree51
etc etc

I can even have this list of files that return the customer # directed to an outfile - if that helps.

How would I have ONLY the files that return the "Customer #" string renamed to have:
"Customer #".pedigree11
"Customer #".pedigree15
"Customer #".pedigree16
"Customer #".pedigree19
"Customer #".pedigree27
"Customer #".pedigree28
"Customer #".pedigree29
"Customer #".pedigree33
"Customer #".pedigree40

So that I could then
MOVE "Customer #".pedigree* C:\pedigrees\Customer #\


I hope that gives clarity to what Im trying to do.

Thanks for your reply faulkner!
johnny5 is offline   Reply With Quote
Old 12-07-2006, 10:45 AM   #4
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
First of all, you would have to have a batch command which pattern matches the "Customer #" string. You can do this with the FOR batch file command using # and a space as the delimiters. You will probably need to read up on the "FOR /?" help and experiment with this, but it can be done.

You may have to get the customer number in 2 passes like so:
Code:
REM **the following is psuedocode, so it may not work in a batch file**
REM this assumes the file's first line is: "Customer #12345 some other text"

REM create a variable where the customer number is the first bit of text
for /F "tokens=2 delims=#" %%a in ('filename.txt') do set temp_customer=%%a

REM remove the text from the end of the customer number, so all we have left is the number
for /F "tokens=1 delims= " %%a in (%temp_customer%) do set customer=%%a
You could then use the find commands to find the string "Customer #%customer%" and use the %customer% variable to organize the files.

I've done stuff like this using command prompt scripts, with PHP. Since it has built-in string parsing functions and can be run from the command line, I would highly recommend this method if you are familiar with PHP.
faulkner132 is offline   Reply With Quote
Old 12-07-2006, 11:39 AM   #5
Member (5 bit)
 
Join Date: Feb 2006
Location: Memphis TN
Posts: 16
Send a message via MSN to johnny5
Ok - let me ask this...

I have a text file that contains a list of filenames. I want to rename only the filenames in that list to add "IPC" to the front of the filename.

Would that be an easier process? Would it still use the FOR command?
johnny5 is offline   Reply With Quote
Old 12-07-2006, 11:58 AM   #6
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Quote:
Originally Posted by johnny5
I have a text file that contains a list of filenames. I want to rename only the filenames in that list to add "IPC" to the front of the filename.

Would that be an easier process? Would it still use the FOR command?
That makes it much easier. Your batch file would look like this:

Code:
for /F "tokens=1 delims= " %%a in ('FileList.txt') do xcopy "c:\current_file_dir\%%a" "c:\copy_to_dir\IPC_%%a"
This assumes your FileList.txt file is in the format:
File1.txt
File2.txt
File3.txt
etc.

And you do not have the full path for each entry, rather just the name of the file.
faulkner132 is offline   Reply With Quote
Old 12-07-2006, 01:31 PM   #7
Member (5 bit)
 
Join Date: Feb 2006
Location: Memphis TN
Posts: 16
Send a message via MSN to johnny5
Great!

It worked. I had to make other modifications to it due to a monkey wrench that got thrown in, but as for getting them renamed, it was exactly what I needed.

Thanks alot for your help Faulkner!
johnny5 is offline   Reply With Quote
Old 12-07-2006, 01:52 PM   #8
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
Glad it worked.

FYI- If you need to do more complex stuff from batch scripts, look into using PHP from the command line... it is very powerful when combined with DOS scripts.
faulkner132 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
External Dvd Burner Not Working PreDeadMan Computer Hardware 1 09-17-2005 03:48 PM
Antivirus broken, HJT logfile EDB Networking & Online Security 6 09-12-2005 12:21 PM
Simple"Copy" batch file bozo Windows Legacy Support (XP and earlier) 33 12-19-2004 08:12 AM
Help! I think I've been hijacked ?? fc3646 Networking & Online Security 11 06-04-2004 12:27 PM
Batch file improvements JIMBOB Windows Legacy Support (XP and earlier) 4 05-12-2004 08:16 AM


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