Solved Help renaming a .txt file in a .BAT file

Golden

000
VIP
SF Team
Local time
2:07 AM
Messages
19,301
Location
South Australia
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 Computer My Computer

At a glance

Windows 10 Pro x64 ; Xubuntu x64Intel i7 860 @ 2.80 GHz O/C'ed to 4.0GHz16GB Corsair Vengance DDR3 @ 661 MHz Dual Cha...EVGA NVidia GTX 560 1024MB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Golden Mk. I.4
OS
Windows 10 Pro x64 ; Xubuntu x64
CPU
Intel i7 860 @ 2.80 GHz O/C'ed to 4.0GHz
Motherboard
Gigabyte P55A-UD3R Rev.1. Award BIOS F13
Memory
16GB Corsair Vengance DDR3 @ 661 MHz Dual Channel (9-9-9-24)
Graphics Card(s)
EVGA NVidia GTX 560 1024MB
Sound Card
Realtek Integrated
Monitor(s) Displays
Dual Samsung SyncMaster 2494HS
Screen Resolution
1920*1080 and 1920*1080
Hard Drives
1*Samsung 840 EVO 120GB SSD;
1*OCZ Vertex 2 60GB SSD;
2*Samsung F3 SpinPoint 1TB in RAID0;
1*Samsung F1 SpinPoint 1TB;
2*Western Digital 1TB External USB 3.0
1*Western Digital 500GB External USB 3.0
1*Seagate 500GB External USB 2.0
PSU
Thermaltake ToughPower QFan 750W
Case
Thermaltake Element S VK60001W2Z
Cooling
Corsair H60 Water Cooling, 2*230mm and 2*80mm case fans
Keyboard
Logitech G110
Mouse
Logitech MX518
Hi -

Try this batch code -
Code:
[font=lucida console]
@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%
[/font]

If backup_log.txt is still in-use (you get an "access denied" error), use copy in place of rename -

Code:
[font=lucida console]
@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%
[/font]

End result = backup_log.txt is renamed/copied to Sat_12-10-2011_backup_log.txt - if run today.

Regards. . .

jcgriff2

`
 

My Computer My Computer

At a glance

Windows 7 - Vista
OS
Windows 7 - Vista
Excellent - that did the trick. Thanks mate.
 

My Computer My Computer

At a glance

Windows 10 Pro x64 ; Xubuntu x64Intel i7 860 @ 2.80 GHz O/C'ed to 4.0GHz16GB Corsair Vengance DDR3 @ 661 MHz Dual Cha...EVGA NVidia GTX 560 1024MB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Golden Mk. I.4
OS
Windows 10 Pro x64 ; Xubuntu x64
CPU
Intel i7 860 @ 2.80 GHz O/C'ed to 4.0GHz
Motherboard
Gigabyte P55A-UD3R Rev.1. Award BIOS F13
Memory
16GB Corsair Vengance DDR3 @ 661 MHz Dual Channel (9-9-9-24)
Graphics Card(s)
EVGA NVidia GTX 560 1024MB
Sound Card
Realtek Integrated
Monitor(s) Displays
Dual Samsung SyncMaster 2494HS
Screen Resolution
1920*1080 and 1920*1080
Hard Drives
1*Samsung 840 EVO 120GB SSD;
1*OCZ Vertex 2 60GB SSD;
2*Samsung F3 SpinPoint 1TB in RAID0;
1*Samsung F1 SpinPoint 1TB;
2*Western Digital 1TB External USB 3.0
1*Western Digital 500GB External USB 3.0
1*Seagate 500GB External USB 2.0
PSU
Thermaltake ToughPower QFan 750W
Case
Thermaltake Element S VK60001W2Z
Cooling
Corsair H60 Water Cooling, 2*230mm and 2*80mm case fans
Keyboard
Logitech G110
Mouse
Logitech MX518
Back
Top