Solved Creating a FOR loop to replace certain letters in a variable

December 13, 2013 at 00:04:18
Specs: Windows 7 Home Premium, 2.4GHz
I am creating a backup program. It is to create a folder named after the date and time of the backup and copy a folder into it. I use %TIME% to alter the time (in this format: 8:57:01,35). Since folder names can't contain colons, I need something that can replace it with something else.

Here's the code:
@Echo off
cd "%~dp0"
title Automatic Backup Utility
goto backup
:main
Echo.
Echo Waiting 30 minutes...
timeout /NOBREAK 1800 > nul
goto backup
:backup
cls
Echo Creating backup...

REM I need a way to replace the colons in the %TIME% variable with letters that can be used in folder names

set backDate=%date%
set backTime=%newTime%
mkdir "Backup\%backDate%__%backTime%"
xcopy /e /q "FOLDER" "Backup\%backDate%__%backTime%"
xcopy /e /q "file1.txt" "Backup\%backDate%__%backTime%"
xcopy /e /q "file2.txt" "Backup\%backDate%__%backTime%"
cls
Echo Done
goto main

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner


See More: Creating a FOR loop to replace certain letters in a variable

Report •


#1
December 13, 2013 at 03:17:47
✔ Best Answer
Replace : with - by coding

set mytime=%time%
set mytime=%mytime::=-%


Report •
Related Solutions


Ask Question