Computing.Net > Forums > Programming > Batch file commands help !

Batch file commands help !

Reply to Message Icon

Original Message
Name: anamica
Date: February 7, 2008 at 06:43:48 Pacific
Subject: Batch file commands help !
OS: windows xp
CPU/Ram: 256 mb
Model/Manufacturer: hp1440
Comment:


Hi,

I need some help with the batch file commands; I have an 'invoice' directory which will have files with below names.

IMPORT_INVOICE_FILEfsbc.20080108.0500368
IMPORT_INVOICE_FILEcount.sbc.20080108.0500368

Prefixes in both the files IMPORT_INVOICE_FILEfsbc. , IMPORT_INVOICE_FILEcount.sbc. will always be same, only the timestamp (YYYYMMDD.HHMMSS) varies from day to day files.

I would like to copy both these files to a different directory with names like below, just by stripping the prefix (IMPORT_INVOICE_FILE)

fsbc.20080108.0500368
count.sbc.20080108.0500368

Any help in this regards is greatly appreciated.

Thanks, Anamica



Report Offensive Message For Removal

Response Number 1
Name: IVO
Date: February 7, 2008 at 08:23:47 Pacific
Subject: Batch file commands help !
Reply: (edit)

The following batch does the job; replace MY_DIRECTORY with the folder holding the files and NEW_DIRECTORY with the target one.

@Echo Off
SetLocal EnableDelayedExpansion
PushD MY_DIRECTORY
For %%j in (IMPORT_INVOICE_FILE*.*) Do (
Set file=%%j
Set file=!file:IMPORT_INVOICE_FILE=!
Copy %%j NEW_DIRECTORY\!file!
)
PopD
:: End_Of_Batch


Report Offensive Follow Up For Removal

Response Number 2
Name: anamica
Date: February 7, 2008 at 09:27:01 Pacific
Subject: Batch file commands help !
Reply: (edit)

Thank you very much :-) It worked like a charm!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file commands help !

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software