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 renaming files but not double

09 Jun 2014   #1
Sygron

Windows 7 Ultimate Edition (64-bit) Service Pack 1
 
 
Batch file renaming files but not double

Hello,

Got another batch file question.
I think I`m close but I`m overlooking something.
I have some logging that will get the date of today when I log off.
But now if I log off twice the file won`t rename, filename already exists.
So I came with a script to just add a number behind the file if it already exists.

And here is the problem it doesn`t work but I can`t seems to find out why it won`t work.
Hopefully an extra pair of eyes can help me out

This is what I got so far:

@ echo off
set jaar=%date:~9,4%
set maand=%date:~6,2%
set dag=%date:~3,2%
set restartvar=1
if exist "D:\test\HardwareMonitoring %jaar%-%maand%-%dag%.txt" (
goto restart
) else (
goto shutdown
)
:restart
if exist "D:\test\HardwareMonitoring %jaar%-%maand%-%dag% [%restartvar%].txt"(
set /A restartvar=%restartvar%+1
goto restart
) else (
ren "D:\test\HardwareMonitoring.hml" "HardwareMonitoring %jaar%-%maand%-%dag% [%restart%].txt"
)
:shutdown
ren "D:\test\HardwareMonitoring.hml" "HardwareMonitoring %jaar%-%maand%-%dag%.txt"

The first file that is in that folder just renames so no problems there.
It seems there is a problem in the restart loop.

Hope that you can find the solution to my problem


My System SpecsSystem Spec
.
10 Jun 2014   #2
Sygron

Windows 7 Ultimate Edition (64-bit) Service Pack 1
 
 

isn`t there anyone who knows what goes wrong with the script?
Really thought I overlooked something simple...
My System SpecsSystem Spec
11 Jun 2014   #3
Sygron

Windows 7 Ultimate Edition (64-bit) Service Pack 1
 
 

Isn`t there anyway to solve this?

Maybe someone knows a different way how I can solve the problem, maybe write it to the original log file of the current date that it adds but doesn`t overwrite?
My System SpecsSystem Spec
.

11 Jun 2014   #4
Sygron

Windows 7 Ultimate Edition (64-bit) Service Pack 1
 
 

Oké as apparently nobody is able to find a solution I try it on a different way.
Trying to copy all the text from the log file to the already existing logfile.
And deleting the logfile so it will start over:

@ echo off
type "D:\test\HardwareMonitoring.hml"
set jaar=%date:~9,4%
set maand=%date:~6,2%
set dag=%date:~3,2%
set restartvar=1
set /P logging="D:\test\HardwareMonitoring.hml"

if exist "D:\test\HardwareMonitoring %jaar%-%maand%-%dag%.txt" (
goto restart
) else (
goto shutdown
)
:restart
echo Computer is herstart! >> "D:\test\HardwareMonitoring %jaar%-%maand%-%dag%.txt"
echo %logging% >> "D:\test\HardwareMonitoring %jaar%-%maand%-%dag%.txt"
del "D:\test\HardwareMonitoring.hml"
goto ending
:shutdown
ren "D:\test\HardwareMonitoring.hml" "HardwareMonitoring %jaar%-%maand%-%dag%.txt"
:ending

All goes well in this file except for one thing.
I can only copy one line of text, the first line to be exact.
The logfile is alot more then just one line.
So new question
Anybody knows a way of copying the content of an entire file to the renamed file?

Hope there is someone out there that can help me out.
My System SpecsSystem Spec
14 Jun 2014   #5
Sygron

Windows 7 Ultimate Edition (64-bit) Service Pack 1
 
 

Come one is there really nobody that knows how I can make this work, any way that works?

Just don`t want to overwrite the file any working suggestion is welcome, even an idea that I may have missed myself...
My System SpecsSystem Spec
14 Jun 2014   #6
Sygron

Windows 7 Ultimate Edition (64-bit) Service Pack 1
 
 

Solved my own problem now.
Instead of writing it the lines of the new file to the old file.

I know just let the computer check with start up if there is a log file of the current date.
If this is the case, the script renames the file back to the original name and thus writing further in this file.
And rename it again with shutdown.

If the date doesn`t exist a new file will be created.
My System SpecsSystem Spec
Reply

 Batch file renaming files but not double




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
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
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
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
renaming files - file name too large? how to disable this?
So I'm renaming some songs but when I do this I get this message: http://i44.tinypic.com/15etpgh.png But my filename is not that long! Here is how long I can make it before my keyboard does not enter characters. They just don't show up when I type. ...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion
Governing files & Can UAC Block/Warn Before File Moving/Renaming?
You know how UAC (user account Control) asks for permission when executing certain programs or when renaming or modding certain files in certain directories? Well i wish i could have it govern over many other folders and files because i tend to accidentally move my hand when double-clicking...
Customization


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 01:16.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App