1.

Solve : getting stuck with rename scripts?

Answer»

I am trying to create a .bat that will move, rename (filename - date) and zip a number of files.

i have got so far and the files move successfully but the rename doesnt seem to work - i dont get any error messages back though.

also i cannot find a command which will create a zipped folder with the new files in it. i have tried wzzip, pkzip and zip but none are recognised commands.

does anyone have any suggestions?

MOVE /-y c:\Responsebackup\* c:\responsearchive\

set mm= %Date:~3,2%
set dd = %Date:~0,2%
set yy = %Date:~8,2%
for %%i in (c:\Responsearchive.*) do ren %%i %%dd-%mm-%yy.TXT


Many thanks
There are different types of variables. There are FOR LOOP variables that look like %%a or %%b , and there are also regular variables that are %variablename%. When you define dd, mm and yy, you have to wrap them in % because they are regular variables. C:\batch>type kizzie.bat

Code: [Select]@echo off
setlocal enabledelayedexpansion

copy c:\batch\backup\* c:\batch\archive\

echo Date = %date%

set mm=%Date:~4,2%
echo mm =%mm%

set dd=%Date:~0,2%
echo dd =%dd%

set yy=%date:~10,4%

echo yy =%yy%

dir c:\batch\archive\


dir /b c:\batch\archive\* > arc.txt


for /F "delims=" %%a in (arc.txt)do (ren "c:\batch\archive\%%a" "%dd%%mm%%yy%.txt" )

dir c:\batch\archive\
OUTPUT:

C:\batch>
C:\batch> kizzie.bat
c:\batch\backup\liz1212.txt
c:\batch\backup\liz1213.txt
2 file(s) copied.
Date = Sun 12/13/2009
mm =12
dd =Su
yy =2009
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of c:\batch\archive

12/13/2009 06:01 PM .
12/13/2009 06:01 PM ..
12/13/2009 12:25 PM 13 liz1212.txt
12/13/2009 12:25 PM 13 liz1213.txt
12/13/2009 12:25 PM 13 Su12 2009.txt
3 File(s) 39 bytes
2 Dir(s) 305,513,332,736 bytes free

Directory of c:\batch\archive

12/13/2009 06:01 PM .
12/13/2009 06:01 PM ..
12/13/2009 12:25 PM 13 liz1212.txt
12/13/2009 12:25 PM 13 liz1213.txt
12/13/2009 12:25 PM 13 Su12 2009.txt
3 File(s) 39 bytes
2 Dir(s) 305,513,332,736 bytes free
C:\batch>

P.s. ren has duplicate problemsQuote from: Kizzie on December 13, 2009, 07:05:09 AM

I am trying to create a .bat that will move,copy, rename (filename - date)
I have got so far and the files move successfully but the rename doesnt seem to work - i dont get any error messages back though.

The rename above wouldhave produced duplicate names ( the system would not allow.)

The following uses the ORIGINAL name as part of the following new name.
( now the name is too long. ). Play with it to reduce name size. GOOD luck. )


for /f "delims=" %%a in (arc.txt) do (ren "c:\batch\archive\%%a" "%%a %dd%%mm%%yy%.txt" )

C:\batch>kizzie.bat
c:\batch\backup\liz1212.txt
c:\batch\backup\liz1213.txt
2 file(s) copied.
Date = Sun 12/13/2009
mm =12
dd =Su
yy =2009
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of c:\batch\archive

12/13/2009 06:01 PM .
12/13/2009 06:01 PM ..
12/13/2009 12:25 PM 13 liz1212.txt
12/13/2009 12:25 PM 13 liz1213.txt
12/13/2009 12:25 PM 13 Su12 2009.txt
3 File(s) 39 bytes
2 Dir(s) 305,543,217,152 bytes free
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of c:\batch\archive

12/13/2009 09:03 PM .
12/13/2009 09:03 PM ..
12/13/2009 12:25 PM 13 liz1212.txt Su12 2009.txt
12/13/2009 12:25 PM 13 liz1213.txt Su12 2009.txt
12/13/2009 12:25 PM 13 Su12 2009.txt Su12 2009.txt
3 File(s) 39 bytes
2 Dir(s) 305,543,213,056 bytes free
C:\batch>

p.s. A full path to the name ( for ren ) of the original file works best. The file with the new name must remain in the same folder. copy or xcopy are more versatile.Thankyou this second one worked great


Discussion

No Comment Found