Renaming multiple file using Batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AlwaysConfused
Posts: 2
Joined: 06 Aug 2012 01:05

Renaming multiple file using Batch

#1 Post by AlwaysConfused » 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 :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Renaming multiple file using Batch

#2 Post by foxidrive » 06 Aug 2012 03:43

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

AlwaysConfused
Posts: 2
Joined: 06 Aug 2012 01:05

Re: Renaming multiple file using Batch

#3 Post by AlwaysConfused » 06 Aug 2012 04:39

Thanks a Lot foxdrive... its working correctly now.. :D

Post Reply