Reputation: 891
I am trying to do a batch file (I have windows 7) to do search for a folder and if it is existed so copy it under name folder backup and delete the folder and then again create new folder and make a copy of another folder to the new one. But the thing that every time it create the folder backup even though the folder that I searched for it at the beginning is not existed.
Any suggestions?
@echo off
dir /b C:\ >> "C.txt"
findstr /m "Folder" C.txt
del C.txt
if NOT %errorlevel%==0 (
goto :continue
) else (
mkdir C:\FolderBackUp
xcopy /s /e "C:\Folder" C:\FolderBackUp
rmdir /s /q "C:\Folder"
)
:continue
mkdir "C:\Folder"
xcopy /s /e "c:\Folder1\Folder2" C:\Folder
goto:eof
Upvotes: 1
Views: 82
Reputation: 37589
one suggestion:
@ECHO OFF &SETLOCAL
IF EXIST "C:\folder\" (
mkdir "C:\FolderBackUp"
xcopy /s /e "C:\folder\" "C:\FolderBackUp\"
rmdir /s /q "C:\Folder"
)
mkdir "C:\Folder"
xcopy /s /e "c:\Folder1\Folder2" "C:\Folder\"
goto:eof
Upvotes: 2