I am trying to create at batch file that will add the date/time into a file name, I need to keep the original file name intact but have the date/time reference to avoid duplication
The following is Sidewinder's code ( post 1) with slight modification and the output is listed. What does pop and push do? How does set search=/ and set replace=- work?
C:\batch>type loose.bat
@echo off
setlocal enabledelayedexpansion
pushd %cd%
set search=/
set replace=-
set search1=:
set replace1=.
for /f %%i in ('dir /a-d /b a*.txt') do (
set newName=%%~ni-%date%-%time%
set newName=!newName:%search%=%replace%!
set newName=!newName:%search1%=%replace1%!
copy "%%i" "!newName!%%~xi"
)
popd
Output:C:\batch>loose.bat
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
C:\batch>dir a*Mon*.txt
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3
Directory of C:\batch
11/10/2009 03:24 PM 36 abc-Mon 03-15-2010-12.23.10.21.txt
11/13/2009 01:21 PM 198 abc2-Mon 03-15-2010-12.23.10.21.txt
11/17/2009 05:36 PM 290 abc5-Mon 03-15-2010-12.23.10.21.txt
03/12/2010 08:44 PM 89 all_a-Mon 03-15-2010-12.23.10.21.txt
12/21/2009 01:29 PM 144 arc-Mon 03-15-2010-12.23.10.21.txt
02/07/2010 04:44 PM 94 army-Mon 03-15-2010-12.23.10.21.txt
12/24/2009 09:58 PM 269 awkinfile-Mon 03-15-2010-12.23.10.21.txt
12/23/2009 10:56 PM 39 awlinfile-Mon 03-15-2010-12.23.10.21.txt
8 File(s) 1,159 bytes
0 Dir(s) 297,769,824,256 bytes free
C:\batch>