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
90 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 84

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 54

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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