|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (5 bit)
|
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. |
|
|
|
|
|
#2 |
|
Come in Ray...
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
For example: Code:
xcopy "c:\some path\some file.doc" "c:\copy to path\%filedate%_some file.doc" This would insure each file is named differently from one day to the next. |
|
|
|
|
|
#3 |
|
Member (5 bit)
|
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! |
|
|
|
|
|
#4 |
|
Come in Ray...
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
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. |
|
|
|
|
|
#5 |
|
Member (5 bit)
|
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? |
|
|
|
|
|
#6 | |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
Quote:
Code:
for /F "tokens=1 delims= " %%a in ('FileList.txt') do xcopy "c:\current_file_dir\%%a" "c:\copy_to_dir\IPC_%%a"
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. |
|
|
|
|
|
|
#7 |
|
Member (5 bit)
|
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! |
|
|
|
|
|
#8 |
|
Come in Ray...
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |