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
79 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 83

Accepted Solution

by:
oBdA earned 250 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 250 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HP PC Hardware Diagnostics UEFI 11 113
Robocopy command line 6 49
xcopy loop 13 37
How To Run a Desktop Icon That Will Open Windows Explorer To Desired Directory 3 20
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now