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
103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 56

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

630 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