Version backups and restoring latest backup with robocopy - batch-file

I am trying to write a batch file and use the robocopy command to backup a directory. However, I need multiple backups to be kept. Let's say I have a directory "A" in "C:\Source Path" and a backup location "C:\Backup Path".
I need the following to happen:
During the backup, If "C:\Backup Path\A Dir" already exists then the copy result should make "C:\Backup Path\A Dir2"; or a similar numbering system.
During the restore, the highest-numbered backup directory in "C:\Backup Path" should replace "C:\Original Path\A Dir"
My current script does not do any versioning and looks like below:
#echo off
set originalPath="C:\Original Path\A"
set backupPath="C:\Backup Path\A"
:L1
echo 1. Backup save files
echo 2. Restore save files
echo 3. Exit
set /p choice=Select an option:
if %choice% equ 1 goto :BACKUP
if %choice% equ 2 goto :RESTORE
if %choice% equ 3 goto :EOF
goto :L1
:BACKUP
robocopy %originalPath% %backupPath% /E
goto :L1
:RESTORE
robocopy %backupPath% %originalPath% /E
goto :L1
:EOF
Is such an operation possible using robocopy alone?

Related

Two-way folder sync with robocopy

So I've been trying to write a batch file which will sync my local Google Drive folder with my flash drive when I run it. Since robocopy is a one-way process, I set up my code so it asks you whether you want to either sync TO Google Drive or FROM Google Drive. This is so that regardless of which of the two locations I make or edit something, I can always sync the newest version onto both locations.
Before anything happens, the code also verifies that it's plugged into my computer and not someone else's by checking its name.
This is what my code looks like right now:
#echo off
If "%computername%"=="JAKE-PC" (
color 02
set /P c=Sync TO or FROM Google Drive[T/F]?
:choice
if /I "%c%" EQU "T" goto :to
if /I "%c%" EQU "F" goto :from
goto :choice
:to
echo Syncing to Google Drive...
robocopy ".\Google Drive\ " "C:\Users\Jake\Google Drive\ " * /mir /xo
goto :done
:from
echo Syncing from Google Drive...
robocopy "C:\Users\Jake\Google Drive\ " ".\Google Drive\ " * /mir /xo
goto :done
:done
echo Sync Complete.
pause
)
If NOT "%computername%"=="JAKE-PC" (
color 04
echo Not Jake's PC!
pause
)
It seems to work okay. If I make a change on the flash drive, I run the batch file and type T which will sync my changes to Google Drive. If I make a change on Google Drive, I type F which will sync changes from Google Drive.
There's only one flaw however, and that's if each location has new content to sync. If I create "a.txt" on my flash drive and "b.txt" on Google Drive, and then if I:
-sync TO Google Drive, a.txt is copied to Google Drive from my flash drive but b.txt is gone from both.
-sync FROM Google Drive, b.txt is copied to my flash drive from Google Drive but a.txt is gone from both.
So this causes the problem of files being lost forever if there's new content on both locations. Is there any way to fix this? I just need a two-way method of syncing both locations without the possibility of losing files/folders from one of them. Maybe even without robocopy.
As per ROBOCOPY /? (or ROBOCOPY.exe doc), /MIR option forces implicite /PURGE:
/MIR : MIRror a directory tree - equivalent to /PURGE plus all subfolders (/E)
/PURGE : Delete destination files/folders that no longer exist in source.
/XO : eXclude Older - if destination file exists and is the same date or newer
than the source - don’t bother to overwrite it.
/E : Copy Subfolders, including Empty Subfolders.
Use /E instead of /MIR option and perform copy in both ways unattended:
#echo off
If "%computername%"=="JAKE-PC" goto :sync
color 04
echo Not Jake's PC!
goto :done
:sync
color 02
:to
echo Syncing to Google Drive...
robocopy ".\Google Drive\\" "C:\Users\Jake\Google Drive\\" * /E /XO
:from
echo Syncing from Google Drive...
robocopy "C:\Users\Jake\Google Drive\\" ".\Google Drive\\" * /E /XO
echo Sync Complete.
:done
pause
Or something similar to next code snippet (keeping set /P user's interpelation):
#echo off
SETLOCAL EnableExtensions
If "%computername%"=="JAKE-PC" goto :sync
color 04
echo Not Jake's PC!
goto :done
:to
echo Syncing to Google Drive...
robocopy ".\Google Drive\\" "C:\Users\Jake\Google Drive\\" * /E /XO
goto :eof
:from
echo Syncing from Google Drive...
robocopy "C:\Users\Jake\Google Drive\\" ".\Google Drive\\" * /E /XO
goto :eof
:sync
color 02
set /P c=Sync TO or FROM Google Drive or BOTH or NOTHING [T/F/B/N]?
if /I "%c%" EQU "T" ( call :to
goto :done
)
if /I "%c%" EQU "F" ( call :from
goto :done
)
if /I "%c%" EQU "B" (
call :to
call :from
goto :done
)
if /I not "%c%" EQU "N" goto :sync
echo No Sync
:done
echo Sync Complete.
pause
Note that if Command Extensions are disabled GOTO will no longer recognise the :EOF label (use exit /B instead of goto :EOF in the case). Although Command Extensions are enabled by default, we can't presume in it. That's why I use SETLOCAL EnableExtensions as a matter of general principle.
If Command Extensions are enabled GOTO changes as follows:
GOTO command now accepts a target label of :EOF which transfers
control to the end of the current batch script file. This is an easy
way to exit a batch script file without defining a label.
Type CALL /? for a description of extensions to the CALL command
that make this feature useful.
Also note that Using GOTO within parentheses - including FOR and IF commands - will break their context.
/XX switch to eXclude eXtra files and directories should do what you need as per this answer:
An "extra" file is present in destination but not source; excluding extras will prevent any deletions from the destination.

How to rename a folder on flash drive using a batch file

I am trying to make a batch file that will back up the contents of a folder onto my flash drive and rename the previous folder on the flash drive. Here is the code.
#echo off
echo Are you sure you want to erase the previous backup file? (Y,N)
set /p ans=
if %ans%==Y goto Backup
goto Exit
:Backup
rd "E:\Batch\BFiles Backup" /s
ren "E:\Batch\BFiles" "BFiles Backup"
:Copy
mkdir E:\Batch\BFiles
xcopy C:\Users\Habib\Documents\BFiles /E /Y E:\Batch\BFiles
echo Files have successfully been copied!
pause
:Exit
exit
When I run the batch file, it copies the files but doesn't rename the already existing folder because "Access is denied". I have tried running it in the administrator version of Cmd, but it still didn't work. My user is an administrator also, so i don't know why access has been denied.
First thing, remove your #ECHO OFF until you are done debugging your code..
Add PAUSE statements so you can stop and see what is going on..
Let's re-format your code a bit..
ECHO Are you sure you want to erase the previous backup file? (Y,N)
set /p ans=
if %ans%==Y goto Backup
PAUSE
goto Exit
:Backup
PAUSE
IF EXIST "E:\Batch\BFiles Backup\." rd "E:\Batch\BFiles Backup" /s
PAUSE
IF NOT EXIST "E:\Batch\BFiles Backup\." ren "E:\Batch\BFiles" "BFiles Backup"
PAUSE
:Copy
IF NOT EXIST "E:\Batch\BFiles\." mkdir E:\Batch\BFiles
PAUSE
xcopy C:\Users\Habib\Documents\BFiles /E /Y E:\Batch\BFiles
IF errorlevel 0 echo Files have successfully been copied!
pause
:Exit
exit
Then, when things start looking correct, remove the PAUSE statements one by one...
Hope this helps!

Batch Coding - Choose command not returning the correct answer

I am trying to create a batch file which has two options:
Create a series of folders with custom names (defined by variables inputted by the user)
OR
Create the same as before except also, once completed, automatically
copying all appropriate files to the appropriate folders in the
structure.
The idea is that with this batch file I could keep my film projects (As I am a freelance filmmaker working with my brother) in exactly the same folder structures across all 3 of our computers. AKA a uniform Project folder structure can be implemented with a simple double click and a few variables to fill in, while in the case of option 2 any files found on a specified SD Card are also moved to the appropriate folders within the structure.
The actual xcopy commands and mkdir commands etc. work exactly how they are supposed to.
Since the different computers will be allocating different drive letters depending on what is already attached to the computer before entering the SD Card into the card reader, I will never know what the drive letter of the SD Card will be (from which the footage and images will be loaded onto the computers).
For example:
One computer could have an external hard drive in (of which we have a few) at the time of the SD Card being plugged in, while another may have only the SD Card as an external device.
The code below is the complete .bat file including past code which I had tried but didn't work or needed to be excluded for some reason. I have some lines of code in comments so I know what I had tried in the past, these are obviously not meant to be used anymore.
:Menu
ECHO OFF
CLS
ECHO OFF
TITLE Saborknight Productions - Project Creator
ECHO.
ECHO ...............................................
ECHO PRESS the appropriate number to select your task, or 3 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Create Saborknight Default folder Hierarchy within a project folder
::(Disabled)ECHO 2 - Create Saborknight Default folder Hierarchy AND copy ALL files from SD Card to the appropriate folder
ECHO 3 - EXIT
ECHO.
ECHO WARNING - Option 2 will delete the files from the Recording Device automatically. Secure the device before proceeding!
ECHO.
ECHO.
CHOICE /c 123 /n
IF ERRORLEVEL 3 EXIT
IF ERRORLEVEL 2 GOTO :CREATE
IF ERRORLEVEL 1 GOTO :CREATE
::End of Menu
---------------------------------------------------------------------------------------------
:CREATE
::Creates DIR Folder Structure as per Saborknight Productions Standard
ECHO OFF
CLS
::Variables Descriptor
SET /P project_name=Enter the Project Name: || SET project_name=NothingChosen
If "%project_name%"=="NothingChosen" (
GOTO ERROR_PROJECT
) ELSE (
GOTO CREATOR
)
:ERROR_PROJECT
::If no Project Name is entered
ECHO Please enter the Project Name
GOTO CREATE
:CREATOR
::DIR Creator + Confirmation
::Videos DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Footage
::Cut from above MKDIR -> \"Day 1"\%device_name%
::Images DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Images\%device_name%
::Audio DIR -> Soundtracks
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Soundtracks
::Audio DIR -> Recordings
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Recordings
::Audio DIR -> Sound FX
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\"Sound FX"
::Premier Project DIR
ECHO OFF
MKDIR D:\Dropbox\"Project Files"\"%project_name%"
ECHO The Folder Structure has been created
ECHO.
ECHO.
ECHO What would you like to do next?
Echo.
ECHO 1 - View Created Folder Structure
ECHO 2 - Go to Menu
ECHO 3 - EXIT
::Choice is invisible
CHOICE /c 123 /n
IF ERRORLEVEL 3 EXIT
IF ERRORLEVEL 2 GOTO MENU
IF ERRORLEVEL 1 GOTO VIEW
::End of CREATE
---------------------------------------------------------------------------------------------
:COPY
::Creates DIR Folder Structure as per Saborknight Productions Standard + Copying/Moving Files from a selected SD Card connected to the computer
ECHO OFF
CLS
:COPY_PROJECT
::Project Variable Descriptor
SET /P project_name=Enter the Project Name: || SET project_name=NothingChosen
If "%project_name%"=="NothingChosen" (
GOTO ERROR_COPY_PROJECT
) ELSE (
GOTO COPY_DEVICE_NAME
)
::If True, Process continues
:COPY_DEVICE_NAME
::Device Name Variable Descriptor
ECHO.
SET /P device_name=Enter the Name of the Recording Device: || SET device_name=NothingChosen
If "%device_name%"=="NothingChosen" (GOTO DAMN_DEVICE) ELSE (GOTO DEVICE_DIR)
:DEVICE_DIR
::Device DIR Variable Descriptor
ECHO.
::Selecting the location of the SD Card of the Recording Device + Confirmation
ECHO Copy files from drive: E, F, G, H or I?
SET _drive=G
::SETLOCAL EnableDelayedExpansion
::CHOICE /c fgehi
::IF ERRORLEVEL 5 SET _drive=I
::IF ERRORLEVEL 4 SET _drive=H
::IF ERRORLEVEL 3 SET _drive=G
::IF ERRORLEVEL 2 SET _drive=F
::IF ERRORLEVEL 1 SET _drive=E
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
::DIR Creator + Confirmation -> Only if Device Drive is successfully selected
::Videos DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"
::Images DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Images\"%device_name%"
::Audio DIR -> Soundtracks
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Soundtracks
::Audio DIR -> Recordings
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Recordings
::Audio DIR -> Sound FX
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\"Sound FX"
::Premier Project DIR
::ECHO OFF
::(Disabled for Testing)MKDIR D:\Dropbox\"Project Files"\"%project_name%"
ECHO.
CHOICE /c YN /m "Would you like files to be deleted automatically from the device? Press Y=Yes or N=No"
IF ERRORLEVEL 2 GOTO NO_DELETE
IF ERRORLEVEL 1 GOTO DELETE
:NO_DELETE
::No Deletion once Copied from Device
::For Copying Videos
ECHO.
ECHO Copying Videos
XCOPY %_drive%:\DCIM\ "D:\Movie Projects\"%project_name%"\Footage\"Day 1"\"%device_name%"\" *.MOV *.mp4 /V /-Y
::COPY %_drive%:\DCIM\ "D:\Movie Projects\"%project_name%"\Footage\"Day 1"\"%device_name%"\" *.MOV *.mp4
::ROBOCOPY %_drive%:\DCIM "D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"\*" *.mov *.mp4 /mir /copy:DATO /np /eta /log+:"Log - Footage CopyOnly.txt" /nosd /nodd
PAUSE
::For Copying Images
ECHO.
ECHO Copying Images
XCOPY %_drive%:\DCIM\ "D:\Movie Projects\"%project_name%"\Images\"%device_name%"\" *.MOV *.mp4 /V /-Y
::COPY %_drive%:\DCIM\*.jpg;*.png;*.cr2 "D:\Movie Projects\"%project_name%"\Images\"%device_name%"\" /V /-Y
::ROBOCOPY %_drive%:\DCIM "D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"" *.jpg *.png *.cr2 /copy:DATO /mir /np /eta /log+:"Log - Images Copy Only.txt" /nosd /nodd
PAUSE
GOTO SUCCESS_MSG
:DELETE
::Copying with Automatic Deletion once Copied
::For Copying and Deleting Videos
ECHO Copying and Deleting Videos
MOVE %_drive%:\DCIM\*.mov;*.mp4 D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"\ /-Y
::ROBOCOPY %_drive%:\DCIM D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%" *.mov *.mp4 /mov /copy:DATO /np /eta /log+:"Log - Footage Copy Delete.txt" /nosd /nodd
PAUSE
::For Copying and Deleting Images
ECHO Copying and Deleting Images
MOVE %_drive%:\DCIM\*.jpg;*.png;*.cr2 D:\"Movie Projects"\"%project_name%"\Images\"%device_name%"\ /-Y
::ROBOCOPY %_drive%:\DCIM D:\"Movie Projects"\"%project_name%"\Images\"%device_name%" *.jpg *.png *.cr2 /mov /copy:DATO /np /eta /log+:"Log - Images Copy Delete.txt" /nosd /nodd
PAUSE
GOTO SUCCESS_MSG
:SUCCESS_MSG
::Only if all Copying/Moving and DIR Creation Processes are Completed Successfully
ECHO.
ECHO The Folder Structure has been created and files copied/moved
ECHO.
ECHO.
ECHO What would you like to do next?
Echo.
ECHO 1 - View Created Folder Structure
ECHO 2 - Go to Menu
ECHO 3 - EXIT
::Choice is invisible
CHOICE /c 123 /n
IF ERRORLEVEL 3 EXIT
IF ERRORLEVEL 2 GOTO MENU
IF ERRORLEVEL 1 GOTO :VIEW
:DAMN_DEVICE
ECHO.
ECHO Please enter the Device Name, Re-entering the Project Name
ECHO.
GOTO COPY
:ERROR_COPY_PROJECT
::If no Project Name is entered
ECHO.
ECHO Please enter the Project Name
ECHO.
GOTO COPY_PROJECT
ENDLOCAL
::End Of COPY
---------------------------------------------------------------------------------------------
:VIEW
ECHO OFF
CLS
TREE D:\"Movie Projects"\"%project_name%"
ECHo.
ECHO Press any key to return to Menu
ECHO.
PAUSE
GOTO MENU
::End of VIEW
The Problem
In this part of the code, the CHOOSE command wont choose the correct choice:
#ECHO OFF
CHOICE /c fgehi
IF ERRORLEVEL 5 SET _drive=I
IF ERRORLEVEL 4 SET _drive=H
IF ERRORLEVEL 3 SET _drive=E
IF ERRORLEVEL 2 SET _drive=G
IF ERRORLEVEL 1 SET _drive=F
Pause
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
The Evidence of the Problem being a problem
I tested the Batch file on two separate machines (One by remote access so that the two screens lay side by side) and can be viewed here: Image of the Problem being a problem...
Apologies for the dirtiest code in history with a complete overuse of comments. This was supposed to be a one night project which has turned into a month long project and I still haven't solved it!
Even a programming friend of mine cannot explain why it wont work.
All help much appreciated in advance!!!
Also any alternative suggestions to complete the described tasks above are definitely welcome, I love learning new code!
Saborknight
Your program fail because IF ERRORLEVEL n ... "execute the command if the errorlevel is GREATER OR EQUAL than the number given", that is, you placed the IF commands in the opposite order. This works correctly:
#ECHO OFF
CHOICE /c fgehi
IF ERRORLEVEL 1 SET _drive=F
IF ERRORLEVEL 2 SET _drive=G
IF ERRORLEVEL 3 SET _drive=E
IF ERRORLEVEL 4 SET _drive=H
IF ERRORLEVEL 5 SET _drive=I
Pause
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
May I suggest you a different, simpler method?
#ECHO OFF
SET option=0FGEHI
CHOICE /c fgehi
CALL SET _drive=%%option:~%ERRORLEVEL%,1%%
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
As documented here: http://www.robvanderwoude.com/choice.php
By the way, in Windows NT 4 this won't work, since the SET command itself will set an errorlevel (usually 0)!
However, Windows NT makes it easy by storing the latest errorlevel in the environment variable ERRORLEVEL
This works for me:
#ECHO OFF
CHOICE /c fgehi
IF %ERRORLEVEL% EQU 5 SET _drive=I
IF %ERRORLEVEL% EQU 4 SET _drive=H
IF %ERRORLEVEL% EQU 3 SET _drive=E
IF %ERRORLEVEL% EQU 2 SET _drive=G
IF %ERRORLEVEL% EQU 1 SET _drive=F
Pause
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
Unless you know the proper ritual to ask the Microsoft gods for forgiveness, I would recommend you stay away from batch, it is a lot of trouble.
Even PowerShell is much less of a hassle.

Creating a Batch to go through all folders on a share and move files

Here is what I am attempting to do and if I can get your help it would be greatly appreciated!
Issue:
I want to create a script to do the following:
Go out to a network share where all account folders exist (2,400 folders with a 9-digit naming convention for account numbers, i.e folder name is 123456789).
Then go through a specific directory within the account folders that have a time stamp naming convention (i.e 123456789\Jan_29_2013_453pm).
Next, all folder structures are the same for all account folders EXCEPT the time stamped folder under the root (i.e 123456789`Jan_29_2013_453pm`\data).
Once being able to get through the time stamp folder there will be a set of folders that start off with a naming convention of media1, media2, media3, media4, media5, etc. that I need to access in order to move files.
I need to move a certain file from all media folders into media1. **There is an unknown amount of media folders for different account folders. Some may have 1 and other may have 50.
I need to run a test within the data folder (123456789\Jan_29_2013_453pm\data) to open a logfile.txt to see if a specific string exists at the end of the log (i.e item was successfully created as well as item has failed`).
If there is a SUCCESSFUL string in the logfile.txt, then go ahead and move all files from other media folders into media1. If a FAILURE string, then output the account folder name to a log file (output.txt) so I am aware which account folders failed (I would append the output as I will run this script multiple times).
The idea is to disregard account folders that have just a single media1 folder. Other account directories that have more than ONE media folder need to run a test against the log for SUCCESS or FAIL and depending on the string, to move a single file from all other media (media2,media3,media4,etc.) folders over to media1 unless FAILURE is read in the log.
I created a text file with all account folders on the share. I'm sure a FOR statement can be used against it. I'm also sure that a FOR statement can be used to go through the log in the "DATA" directory to look for the "SUCCESSFUL" or "FAILED" string.
The hard part I see is being able to get through the time stamped folder in order to get to the DATA directory.
THANKS AGAIN FOR ALL THE HELP!
#echo off
setlocal enabledelayedexpansion
:beginning
echo.
echo.
echo ===========================================================
echo Starting on !date! !time! on !Computername!
echo ===========================================================
echo.
echo Press ENTER to begin...
pause
echo.
goto :main
:main
cls
echo.
set /P acct=Please type the 9 digit account number you would like to restore:
set acctDir=X:\!acct!\
set acctDir2=media1\Setup\setup.exe /cd
set acctDir3=media1
set x=x:\!acct!\!userDir!
set sumLog="x:\!acct!\!userDir!\SummaryLog.txt"
set succ=finished
set log=c:\logs.txt
echo. Starting on !date! !time! on !Computername! >> !log!
echo.
echo The account number you selected is: !acct!
echo.
goto :user
:user
set /p answer=Is this correct (Y/N)?
echo.
if /i !answer!==y goto :yes (
) else (
echo.
echo Ok. Let's try again^^!
echo.
pause
cls
goto :main
)
)
:yes
set c=0
For /f %%a in ('dir !acctDir! /B /A:D') do (
set /a c+=1
echo !c! %%a
set dir!c!=%%a
)
echo.
set /p userIn="Select a directory [1-!c!]: "
set userDir=!dir%userIn%!
echo.
echo You selected !userDir! for your data retrieval.
echo.
goto :execute
:execute
echo.
echo The software will now be installed...
start !acctdir!\!userDir!\!acctDir2! >>!log!
:move
forfiles /p "!acctdir!\!userDir!\" /s /m *.ARC /c "cmd /c move #file !acctdir!\!userDir!\!acctdir3!"
goto
:string
findstr " .*!succ!" !sumLog!
if exist errorlevel 0 (
pause
goto :move
) else (
goto :eof
)
endlocal
goto :eof

Delete .txt files in subfolders using batch script [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Delete files in subfolder using batch script
I have to delete .txt files from a sub folder (with same name). My filepath is like as follows.
d:\test\test1\archive*.txt
d:\test\try\archive*.txt
d:\test\model\archive*.txt
I tried "del" command to delete the ".txt" files in above paths. But there are more than 100 folders in the folder "test". So it is very difficult to use "del" for each and every path.
Except the parent folder name of "archive" folder, everything remains the same for all the paths. So I guess there might be some easy way to delete the files using batch script.
Can anyone guide me whether there is any easy way to delete .txt files using batch script Or I have to repeat "del" for all 100 folders?
del /s *.txt
hope it helps.All the best mate
del /s *.txt will delete all TXT files in all subfolders of current working directory.
(But use that command carefully - wrong parent directory and you are throwing away all textfiles on your computer :) )
Edited
del /s d:\test\archive\*.txt
This should get you all of your text files
Alternatively,
I modified a script I already wrote to look for certain files to move them, this one should go and find files and delete them. It allows you to just choose to which folder by a selection screen.
Please test this on your system before using it though.
#echo off
Title DeleteFilesInSubfolderList
color 0A
SETLOCAL ENABLEDELAYEDEXPANSION
REM ---------------------------
REM *** EDIT VARIABLES BELOW ***
REM ---------------------------
set targetFolder=
REM targetFolder is the location you want to delete from
REM ---------------------------
REM *** DO NOT EDIT BELOW ***
REM ---------------------------
IF NOT DEFINED targetFolder echo.Please type in the full BASE Symform Offline Folder (I.E. U:\targetFolder)
IF NOT DEFINED targetFolder set /p targetFolder=:
cls
echo.Listing folders for: %targetFolder%\^*
echo.-------------------------------
set Index=1
for /d %%D in (%targetFolder%\*) do (
set "Subfolders[!Index!]=%%D"
set /a Index+=1
)
set /a UBound=Index-1
for /l %%i in (1,1,%UBound%) do echo. %%i. !Subfolders[%%i]!
:choiceloop
echo.-------------------------------
set /p Choice=Search for ERRORS in:
if "%Choice%"=="" goto chioceloop
if %Choice% LSS 1 goto choiceloop
if %Choice% GTR %UBound% goto choiceloop
set Subfolder=!Subfolders[%Choice%]!
goto start
:start
TITLE Delete Text Files - %Subfolder%
IF NOT EXIST %ERRPATH% goto notExist
IF EXIST %ERRPATH% echo.%ERRPATH% Exists - Beginning to test-delete files...
echo.Searching for .txt files...
pushd %ERRPATH%
for /r %%a in (*.txt) do (
echo "%%a" "%Subfolder%\%%~nxa"
)
popd
echo.
echo.
verIFy >nul
echo.Execute^?
choice /C:YNX /N /M "(Y)Yes or (N)No:"
IF '%ERRORLEVEL%'=='1' set question1=Y
IF '%ERRORLEVEL%'=='2' set question1=N
IF /I '%question1%'=='Y' goto execute
IF /I '%question1%'=='N' goto end
:execute
echo.%ERRPATH% Exists - Beginning to delete files...
echo.Searching for .txt files...
pushd %ERRPATH%
for /r %%a in (*.txt) do (
del "%%a" "%Subfolder%\%%~nxa"
)
popd
goto end
:end
echo.
echo.
echo.Finished deleting files from %subfolder%
pause
goto choiceloop
ENDLOCAL
exit
REM Created by Trevor Giannetti
REM An unpublished work
REM (October 2012)
If you change the
set targetFolder=
to the folder you want you won't get prompted for the folder.
*Remember when putting the base path in, the format does not include a '\' on the end.
e.g.
d:\test
c:\temp
Hope this helps

Resources