Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Help renaming a .txt file in a .BAT file


10 Dec 2011   #1

Microsoft Community Contributor Award Recipient

Windows 7 Ult. x64 Windows 8.1 x64 Ubuntu 12.04 LTS Tri-Boot
 
 
Help renaming a .txt file in a .BAT file

G'day,

I wonder if someone could point me in the right direction?

I have a .BAT file that uses robocopy to backup my data. Part of the robocopy saves the reuslts into a log file called backup_log.txt

At the end of the .BAT file, once robocopy has been completed and the .txt file has been created, I would like to rename it such that the name of the .TXT file references the data and time.

In the CMD window I see I have access to the date /T command, but for the life of me I cannot figure out how to concatenate these commands with the .txt file. Its easy using the Unix move command..........but I'm stumped in CMD.

My goal is to rename backup_log.txt to Sat 10/12/2011_backup_log.txt.

Can anyone make some suggestions?

Thanks,
Golden

My System SpecsSystem Spec
.

10 Dec 2011   #2

Windows 7 - Vista
 
 

Hi -

Try this batch code -
Code:

@echo off
set x=_backup_log.txt
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set d1=%%a_%%b-%%c-%%d) 
set x2=%d1%%x%
ren backup_log.txt %x2%
If backup_log.txt is still in-use (you get an "access denied" error), use copy in place of rename -

Code:

@echo off
set x=_backup_log.txt
For /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set d1=%%a_%%b-%%c-%%d) 
set x2=%d1%%x%
copy backup_log.txt %x2%
End result = backup_log.txt is renamed/copied to Sat_12-10-2011_backup_log.txt - if run today.

Regards. . .

jcgriff2

`
My System SpecsSystem Spec
12 Dec 2011   #3

Microsoft Community Contributor Award Recipient

Windows 7 Ult. x64 Windows 8.1 x64 Ubuntu 12.04 LTS Tri-Boot
 
 

Excellent - that did the trick. Thanks mate.
My System SpecsSystem Spec
.


Reply

 Help renaming a .txt file in a .BAT file




Thread Tools



Similar help and support threads for2: Help renaming a .txt file in a .BAT file
Thread Forum
Batch File Renaming Possible? Customization
Solved Renaming multiple file extensions at once General Discussion
Help me Deny deleting & renaming file/folder System Security
Solved Renaming Files/File Extensions General Discussion
renaming files - file name too large? how to disable this? General Discussion
File and folder renaming/organising help please. General Discussion
Multiple File Renaming Music, Pictures & Video

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 10:24 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33