I have reviewed the current posts about this subject and have tried the various suggestions for creating the batch file. This is what I have come up with so far. However, the batch file seems to want to only run Copy to Laptop, regardless of the choice selected. Please help!
#ECHO OFF
CLS
ECHO 1.Copy to Desktop?
ECHO 2.Copy FROM Desktop to Flash Drive?
ECHO 3.Copy to Laptop?
ECHO 4.Copy FROM Laptop to Flash Drive?
ECHO.
CHOICE /C 1234 /M "Enter your Choice:"
IF ERRORLEVEL 4 GOTO Copy FROM Laptop to Flash Drive?
IF ERRORLEVEL 3 GOTO Copy to Laptop?
IF ERRORLEVEL 2 GOTO Copy FROM Desktop to Flash Drive?
IF ERRORLEVEL 1 GOTO Copy to Desktop?
:Copy to Laptop?
ECHO Copy to Laptop
xcopy H:\ "C:\Users\8888\Documents\My Games" /e /y
GOTO End
:Copy FROM Laptop to Flash Drive?
ECHO Copy FROM Laptop to Flash Drive
xcopy "C:\Users\8888\Documents\My Games" H:\ /e /y
GOTO End
:Copy to Desktop?
ECHO Copy to Desktop
xcopy H:\ "C:\Users\****\Documents\My Games" /e /y
GOTO End
:Copy FROM Desktop to Flash Drive?
ECHO Copy FROM Desktop to Flash Drive
xcopy "C:\Users\****\Documents\My Games" H:\ /e /y
GOTO End
:End
Spaces are not allowed in GOTO statements.
So all your GOTOs goes to the first :Copy. The rest "to Desktop?" and so on is ignored.
The problem you're having is that all of the labels are using only the first word, which in all cases is COPY (the first space seems to be where it stops looking at the label).
This works perfectly fine for me. Notice that I've changed all of the :Label names to something still meaningful by removing the spaces and the ? at the end. (I also removed the xcopy lines, because they weren't necessary to demonstrate the solution.)
#ECHO OFF
CLS
ECHO 1.Copy to Desktop?
ECHO 2.Copy FROM Desktop to Flash Drive?
ECHO 3.Copy to Laptop?
ECHO 4.Copy FROM Laptop to Flash Drive?
ECHO.
CHOICE /C 1234 /M "Enter your Choice:"
IF ERRORLEVEL 4 GOTO LapTopToFlashDrive
IF ERRORLEVEL 3 GOTO CopyToLaptop
IF ERRORLEVEL 2 GOTO DesktopToFlashDrive
IF ERRORLEVEL 1 GOTO CopyToDesktop
:CopyToLaptop
ECHO Copy to Laptop
GOTO End
:LaptopToFlashDrive
ECHO Copy FROM Laptop to Flash Drive
GOTO End
:CopyToDesktop
ECHO Copy to Desktop
GOTO End
:DesktopToFlashDrive
ECHO Copy FROM Desktop to Flash Drive
GOTO End
:End
Pause
Related
Ive been looking for answer to this question but so far unsucessfully. Can i somehow make it that after batch file is started it wouldnt close if you would press X button on top right (the exit button)? If yes, how to do that?
code for "fake virus"
#echo off
color 47
net stop themes >nul
title DEEP VIRAL INFECTION!
echo VIRAL INFECTION!!!
echo VIRAL INFECTION!!!
echo VIRAL INFECTION!!!
echo ERROR!!!
echo -
echo virus - TROJAN_DEMOLISHER code #45643676
echo -
echo FIREWALL - FAILED
echo -
echo ANTI-VIRUS - FAILED
echo -
echo IP ADDRESS BREACHED!
echo -
echo VIRUS ATTAINING: ****-****-****-8894
echo -
pause
cls
echo -
echo SCANNING INFECTED AREAS...
echo -
pause
title SCANNING INFECTED AREAS...
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
:end
cls
title DEEP VIRAL INFECTION!
echo -
echo 86.5 PERCENT OF MEMORY INFECTED
echo -
echo INFECTION FATAL!
echo -
echo DELETION OF ENTIRE CONTENTS OF LOCAL DISK C: REQUIRED
echo -
pause
cls
echo -
title DELETING HARD-DRIVE C:
echo -
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
cls
title DEEP VIRAL INFECTION!
echo -
echo CONTENTS OF HARD-DRIVE C: ERASED
echo -
pause
cls
echo -
echo SCANNING...
echo -
title SCANNING...
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
:end1
cls
title DEEP VIRAL INFECTION!
echo -
echo 0.00 PERCENT OF HARD-DRIVE INFECTED
echo -
pause
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
pause
cls
title SYSTEM FAILURE
color 17
echo ERROR!
echo -
echo VISUAL MEMORY LOST!
echo -
echo RAM LOST!
echo -
echo CORE PROCESSOR FAILING...
echo -
echo TOTAL SYSTEM CRASH IMMINENT!
echo -
echo -
pause
cls
echo -
echo -
echo -
echo SHUTDOWN COMPUTER NOW TO AVOID RISK OF FIRE!
echo -
echo -
echo -
pause
cls
echo -
echo -
echo -
echo SEEK PROFESSIONAL HELP IMMEDIATLY TO PREVENT FURTHER DAMAGE!
echo -
echo -
echo -
pause
start shutdown /s /t 60 /c "SYSTEM FAILURE<SHUTTING DOWN TO AVOID FURTHER DAMAGE!"
multiple dir lines are to give the effect of smth actually happening
There is no way to avoid that the cmd.exe session be closed when the user press the X button, but your Batch file can start a second cmd.exe session via start command and restart it again as soon as it terminates. If the window size of both the initial and second cmd.exe sessions are adjusted properly, you will get the desired effect.
#echo off
if "%1" equ "Restarted" goto %1
:again
echo N|start "" /WAIT cmd.exe /C "%~F0" Restarted > NUL
goto :again
:Restarted
echo I am a virus!
:loop
echo You can't close me!
timeout /T 1 > NUL
goto loop
Also, you were worried about losing the virus effect. Heres a way to make that not happen
Make another Notepad document and put,
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
pause
Replace The_Name_Of_Virus with the file name of the batch file.
Doing that tells the computer to open the file 5 times. Then if someone closes one of them and it restarts the code, there are still 4 left that are still going. Making it run 5 batch files at the same time will slow your system down a bit. The %username% command uses the username so you do not need to replace %username% with your PC username.
Someone please correct me if I got anything wrong (I don't think I did).
Also, I think you should only put 1 dir command in there because on computers with a lot of filled memory (like mine), it will take a long time to go through every file. I have about 400GB filled on my computer and it took 15mins just to finish the first block of dir commands.
Well instead of deleting task mgr you could just kill taskmgr and then rename it to say nottaskmgr.exe and after the prank thing is done just kill taskmgr and rename it back to taskmgr.exe
Instead of putting "pause" at the end of each speech part you can put
ping -n 2 localhost >nul
That gives it a small delay before moving on the next part.
It basically just tells the system to ping itself and depending on your computer that will take a different amount of time. The 2 is telling the system to ping itself 2 times.
You could copy your .Bat file source and re-create it in a command prompt applications, this will require Visual Studio Community or better.
You can remove this windows Top-Bar utilities through the application frames Properties.
(Use the property tab for this)
You could also make a simple prank virus using a regular windows form application by using the following code with a looped (copy 'n paste) prompt.
MessageBox.Show("message", title);
I hope this helped you.
Yours sincerely,
OTA
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.
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!
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.
Want to make a installer for a game i play:
#echo off
echo.
echo Choose One
echo __________
echo.
echo 32
echo.
echo 64
echo.
echo Idk
echo.
echo __________
echo.
echo.
set/p bit=
goto %bit%
:32
xcopy "warcraft3" C:\Program Files
pause
goto done
:64
xcopy "warcraft3" C:\Program Files(x86)
pause
goto done
:idk
xcopy "warcraft3" C:\Program Files
pause
goto done
:done
the "warcraft3" is a folder not a zip or anything, it says it cant find the specified file.
Need quotes around folders with spaces
xcopy "warcraft3" "C:\Program Files\"
also good practice to put a trailing slash on destination folders.