Renaming multiple file using Batch
Posted: 06 Aug 2012 01:17
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
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
