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
72 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

22 Experts available now in Live!

Get 1:1 Help Now