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: Batch file , change filename with system date and time infor

19 Dec 2010   #1

Windows 7 Ultimate x64
Batch file , change filename with system date and time infor

I wrote a bat file, to change a file name, test.txt to testMonthDayYearTime.txt

here is what i wrote:
ren c:\example\test.txt test%date:~4,2%%date:~7,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%%.txt

But after running, the file name is test12182010 093012.txt, a space is between date and time. I don;t want the space. Anyone know what's wrong.

My System SpecsSystem Spec
19 Dec 2010   #2

Windows 7 Pro x64 SP1

i used the same routine to set an environmental variable with your routine and it
worked fine.

set xx= test%date:~4,2%%date:~7,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%%.txt

xx= test12192010150311.txt

something tells me that your time display settings could be different than mine.

I love batch files.

My System SpecsSystem Spec
19 Dec 2010   #3

Windows 10 Pro X64

You're missing a double quote. Try this:

ren test.txt "test%date:~4,2%%date:~7,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%%.txt"

When I did it from a Command Prompt, I got: test12192010221526.txt

Put it in a batch file and it still works, got: test12192010221739.txt
My System SpecsSystem Spec


 Batch file , change filename with system date and time infor

Thread Tools

Similar help and support threads
Thread Forum
Date and Time - Change
How to Change the Date and Time in Windows 7 This tutorial will show you how to set or change the date and time for the system clock of your PC in Windows 7. You must be logged in as an administrator to be able to change the date and time in Windows.
Batch file that replaces a filename in a txt file
I've got a task that I need to repeat 100 times in a CAD program. I've written a small script in the CAD program that takes a model and does a bunch of things to it, saves it, and closes it. (That part is taken care of, but I want to automate it) That script is written in a text file. But it's...
General Discussion
Is there a Script or batch file that can create folders by date range
I was wondering if there was a way to create a set of folders in a specific directory according to a date range that i input. ie. Select start date 2011 10 01 select end date 2012 10 01 Select Output path of c:\users\XXXX\desktop\export data
General Discussion
How to create a current date folder using batch file?
Hi I am using following batch file for cleaning the desktop and also for taking backup of desktop: @echo off set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% mkdir "%USERPROFILE%\My Documents\backup\%curr_date%_backup"
General Discussion
Change date and time stamp on file save...
When I create a file in Windows 7 and save it I get the current date and time stamp but when I edit the program at a later time and date and save again it doesn't change the date and time stamp it stays the same as the original file! I feel like a moron but how can I change this?
Performance & Maintenance
'Date Modifed' of filename doesn't change
I'm working in AutoCAD, saving a VBA project. The VBA changes are saved in the file, but the Date Modified date in Windows Explorer doesn't change! And the Date Modified reported is OLDER than the Date Created. Not good... anybody else notice this behavior? Any way to fix it? thanks in...
General Discussion

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 09:22.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App