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
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 
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
jcgriff2

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
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

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
Thread Forum
Renaming a sub-folder within a zipped file
I compressed a .crx file. The file structure of the compressed file is Compressed CRX 1Sub-Folder 2Sub-Folder >2file >3file 3Sub-Folder >4file
General Discussion
Batch File Renaming Possible?
is it possible to batch file name in win7? I have many videos and music that needs renaming often but i'm wary of 3rd party apps. I use to use rename-it! back when i had vista and xp but it hasn't been updated for win7
Customization
Renaming multiple file extensions at once
How do i change multiple file extensions name all at once? I have all MKV file and would like to change it in to AVI. This process is taking far too long. Is there a shortcut to this? other than renaming each individual file. Thankyou
General Discussion
Renaming Files/File Extensions
Setup: Win 7 Home Premium SP 1 x64 on Dell Studio 1558. In most directories, if I rename "file.jpg" to... "file.JPG" and hit return to commit the change, "file.jpg" is the result. When I go to rename "file.jpg" again and the text is highlighted, awaiting my input, "file.jpg" turns into......
General Discussion
File and folder renaming/organising help please.
Hello, I seem to remember seeing a tool called file 2 folder which puts a files into thier own folder and names the folder the same as the original file, i have had a search both here and google but have not managed to find it. Any nudge in the right direction would be much appreciated. Also, I...
General Discussion
Multiple File Renaming
OK, hope this is the right forum, it is to do with pictures, amongst other things. I have a strange problem regarding renaming multiple files, mainly pictures as I have tons of them. Whenever I name all pictures in a folder, highlighting them all and renaming the first one, it renames the first 40...
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 05:24.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App