Jump to content

IF EXIST batch command help


Recommended Posts

This is what i want to do. Useing a batch file check to see if a folder called "_User Backup Files\Pictures" exists If this does i want to copy the contents of that file into the My Pictures folder of my user profile. I do not want to move the entire folder and replace the My Pictures folder that is created during install i only want to copy everthing inside my "_User Backup Files\Pictures" so prob something like COPY *.* or something. If the "_User Backup Files\Pictures" folder is empty i want it to say "No backup files to copy" or something. I want to run this same command for a "_User Backup Files\Papers" folder also Does this make sense? I am haveing trouble using the IF Exist and ELSE commands and need help thankyou.

Link to comment
Share on other sites


Hi! :hello:

You could try something like this:

@ECHO OFF
SET SRC=c:\path to backup\*.*
IF EXIST "%SRC%" (
XCOPY "%SRC%" "%USERPROFILE%\My Documents\My Pictures" /E>nul
) ELSE (
ECHO No backup files to copy!
)

Hope this helps

Eki :)

Link to comment
Share on other sites

The following may help too, it will check all your drives for you!

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS
FOR /F %%? IN ('MOUNTVOL ^| FIND ":\"') DO CALL :CHKDRV %%?
IF NOT DEFINED DCTRY (
ECHO/ No Back-ups Directory was found!
) ELSE (
ECHO/ A Back-ups Directory was found at %DCTRY%
XCOPY "%DCTRY%\Pictures" "%USERPROFILE%\My Documents\My Pictures" /E/H/Q/Y 2>NUL || ECHO/ No Picture Backups were found!
XCOPY "%DCTRY%\Papers" "%USERPROFILE%\My Documents" /E/H/Q/Y 2>NUL || ECHO/ No Document Backups were found!
)
PING -n 11 127.0.0.1 >NUL & ENDLOCAL & GOTO :EOF

:CHKDRV
PUSHD %1 >NUL
FOR /F "DELIMS=" %%? IN ('DIR/B/S/AD "_USER BACKUP FILES" ^2^>NUL') DO IF ERRORLEVEL 0 SET DCTRY=%%~f?
POPD & GOTO :EOF

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...