Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I have a batch file from here that checked if the folder existed and renamed it. Can someone help

Posted on 2016-08-08
6
Medium Priority
?
115 Views
Last Modified: 2016-08-08
I have this batch file from this site.

I tried running this but it does not seem to create the folder. I am trying to run this from local disk C: and I want to backup to local disk C: It does not seem to work.
Untitled.jpg
0
Comment
Question by:Vicki05
6 Comments
 

Author Comment

by:Vicki05
ID: 41747671
Here is the batch file. I need to run this to see if the folder exists, then to backup the folder with date and timestamp to a folder in local disk C.

@echo off
setlocal enabledelayedexpansion
set Folder=C:\Temp\Foo
if not exist "%Folder%" goto Continue
REM The next line sets the following DateTime variables: DT_Day, DT_DayOfWeek, DT_Hour, DT_Minute, DT_Month, DT_Quarter, DT_Second, DT_WeekInMonth, DT_Year
for /f "delims=" %%a in ('wmic.exe Path Win32_LocalTime GET * /value') do (for /f "delims=" %%b in ("%%a") do set DT_%%b)
for %%a in (DT_Month DT_Day DT_Hour DT_Minute DT_Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
set TimeStamp=%DT_Year%%DT_Month%%DT_Day%-%DT_Hour%%DT_Minute%%DT_Second%
for %%a in ("%Folder%") do set FolderName=%%~nxa
ECHO ren "%Folder%" "%FolderName%_%TimeStamp%"
if errorlevel 1 (
      echo ERROR: could not rename "%Folder%" to "%FolderName%_%TimeStamp%"
      pause
      exit /b 1
)
:Continue
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1000 total points
ID: 41747684
It doesn't create the folder because the script is in test mode.
In the line ECHO ren "%Folder%" "%FolderName%_%TimeStamp%", remove the ECHO at the beginning.
0
 
LVL 5

Expert Comment

by:Manuel Flores
ID: 41747690
One suggestion somekind off-topic... why don't you use robocopy?.  Is a full featured copy/mirroring utility with several options that includes copy timstamp, owner, permissions, etc...
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 59

Assisted Solution

by:Bill Prew
Bill Prew earned 1000 total points
ID: 41747695
The script is setup to be in "debug" mode, which in this case just means that it isn't set to actually perform the rename, but just to display on the screen the rename command it would execute.  If you really want it to rename then just remove the word "ECHO" from the following line:

ECHO ren "%Folder%" "%FolderName%_%TimeStamp%"

~bp
0
 

Author Comment

by:Vicki05
ID: 41747754
Thanks for your help again.
0
 

Author Closing Comment

by:Vicki05
ID: 41747792
Thanks for all the help.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question