Joe4
MrExcel MVP, Junior Admin
- Joined
- Aug 1, 2002
- Messages
- 74,155
- Office Version
- 365
- Platform
- Windows
I am trying to copy a file from one lcoation to another using a batch (.bat) file, but I am trying to put a date stamp on it.
The trick is I am trying to put it in the middle, and while every file has the same prefix and suffix, but the middles are different (though always the same length).
My file name convention is:
DEP_nnnn.txt
where 'nnnn' = the 4 digit client number
So if I have two files, i.e.
DEP_1234.txt
DEP_0987.txt
I am trying to rename them:
DEP_1234_20060420.txt
DEP_0987_20060420.txt
I tried to do it with wildcards, but it doesn't appear that batch files like "?" as wildcards. Here is what I tried.
Can anyone help?
The trick is I am trying to put it in the middle, and while every file has the same prefix and suffix, but the middles are different (though always the same length).
My file name convention is:
DEP_nnnn.txt
where 'nnnn' = the 4 digit client number
So if I have two files, i.e.
DEP_1234.txt
DEP_0987.txt
I am trying to rename them:
DEP_1234_20060420.txt
DEP_0987_20060420.txt
I tried to do it with wildcards, but it doesn't appear that batch files like "?" as wildcards. Here is what I tried.
Code:
:: *** CAPTURE DATE FOR USE IN RENAMING
C:
CD\
FOR /F "TOKENS=2,3,4 DELIMS=/ " %%I IN ('DATE/T') DO SET D=%%K%%I%%J
:: Put date stamp on files as they are moved to H drive
copy C:\TEMP\DEP_????.txt H:\DEP_????_%d%.txt
exit
Can anyone help?