Page 1 of 1

Renaming multiple file using Batch

Posted: 06 Aug 2012 01:17
by AlwaysConfused
Hello, I was trying to rename and move multiple files from one folder to another. The renaming has to be in the following format.

text_(number)(date)(time).txt

i have four files to move. but the problem is the first renaming of file is not correct. There is no date and time in the first file. The code is as follows
________________________________________________________________________________________________________________
@setLocal EnableDelayedExpansion
set N=0

:LOOP
set /A limit+=1
TIMEOUT 2


FOR %%i IN (D:\user\*.txt) DO (
set /A N+=1

@For /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') Do @(
Set Day=%%B
Set Month=%%C
Set Year=%%D
Set All=%%D%%C%%B

)
@For /F "tokens=1,2,3,4 delims=:,." %%A in ('echo %time%') Do @(
Set Hour=%%A
Set Min=%%B
Set Sec=%%C
Set Allm=%%A%%B%%C
)

move "%%i" D:\user1\text_%N%%All%%Allm%.txt


if !N! geq %limit% GOTO :LOOP
)

::DONE
endlocal

_______________________________________________________________________________________________________

its a bit urgent, so if anyone can help please. Thanks in advance :)

Re: Renaming multiple file using Batch

Posted: 06 Aug 2012 03:43
by foxidrive
Try this: or if you want a dynamic date and time then use your code and this:

move "%%i" D:\user1\text_%N%!All!!Allm!.txt

Code: Select all

@setLocal EnableDelayedExpansion
set N=0

:LOOP
set /A limit+=1
TIMEOUT 2

@For /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') Do @(
Set Day=%%B
Set Month=%%C
Set Year=%%D
Set All=%%D%%C%%B

)
@For /F "tokens=1,2,3,4 delims=:,." %%A in ('echo %time%') Do @(
Set Hour=%%A
Set Min=%%B
Set Sec=%%C
Set Allm=%%A%%B%%C
)




FOR %%i IN (D:\user\*.txt) DO (
set /A N+=1

move "%%i" D:\user1\text_%N%%All%%Allm%.txt


if !N! geq %limit% GOTO :LOOP
)

::DONE
endlocal

Re: Renaming multiple file using Batch

Posted: 06 Aug 2012 04:39
by AlwaysConfused
Thanks a Lot foxdrive... its working correctly now.. :D