Nelson Posted August 2, 2022 Posted August 2, 2022 I have a couple of batch files that run backup programs ... one for a full offsite and another smaller one to backup documents, both going to USB drive D:. The volumes are OFFSITE and SECURITY. My question, is there an "IF EXIST volume name" statement I can use in the code to test that the correct drive has been inserted. I am using a test for the drive being present, simply IF EXIST D:\ GOTO which works fine and I have tried various modifications i.e. D:OFFSITE, OFFSITE (D:) etc, but nothing works and there is nothing on the web of any help. Any ideas would be gratefully received. Existing code for drive check as follows: :retry IF EXIST D:\ GOTO run GOTO noexist :noexist echo a = msgbox(" USB DRIVE IS NOT CONNECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT USB AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto retry if errorlevel 2 goto no No ends program and run runs the robocopy.
Steve21 Posted August 2, 2022 Posted August 2, 2022 Haven’t tested it but should be able to just do something like vol D: | find "Offsite” if not errorlevel 1 goto run Etc Steve 1
Nelson Posted August 3, 2022 Author Posted August 3, 2022 Many thanks Steve ... it works very nicely and has made the two programs virtually bombproof !! They have been compiled to .exe now (iExpress) and tested fully. Below is how I've incorporated the code: Initial messages etc :check1 IF EXIST D:\ GOTO check2 GOTO noexist1 :noexist1 echo a = msgbox(" USB DRIVE IS NOT CONNECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT USB AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check1 if errorlevel 2 goto no :check2 vol D: | find "Security" if not errorlevel 1 goto copy goto noexist2 :noexist2 removedrive D: -L echo a = msgbox(" INCORRECT USB DRIVE HAS BEEN MOUNTED" ^& vbCrLf ^& " VOLUME SECURITY EXPECTED" ^& vbCrLf ^& vbCrLf ^& "PLEASE INSERT CORRECT VOLUME AND RETRY or CANCEL",vbCritical + vbRetryCancel,"Security copy") > "%temp%\popup.vbs echo WScript.Quit a >> "%temp%\popup.vbs" wscript.exe "%temp%\popup.vbs" set "exitcode=%errorlevel%" if errorlevel 4 goto check2 if errorlevel 2 goto no :copy Copy program runs, releases drive then displays report Thank you once again and have a good day.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now