Hello batch users(or batch viewers),
I thought i would make a simple tutorial on how to make a batch file copy a directory into a file called data. Although you cannot copy a directory that has the batch files eomwhee in it even if its in a sub-direcotry.
Ok Lets being.
Steps:
First: Right Click,Select New, Select Notepad/Text Document.
Now select File, Save as, change file type to All files, Call it COPY.bat
right click COPY.bat and select edit
type in the following code to set the colors and title
@echo off
color 0c
(This color code "0c" will set the color of the backgound and the text)
the 0 is for the black background and the c is for red text.
-feel free to play around with these colors.
title Alex's Copying Program
if not exist data MD data
(this will set the title to Alex's Copying program)
and the code *if not exist data MD data* sets it to make a file called data if it already does not exist-this will be the folder that files copy to-
@echo off make you not able to see the code when running the program
Now enter the folowing code to set a password for your program
(this is optional)
:start
cls
echo enter password to continue
set/p pwd="Password: "
if %pwd%==alex goto correct
if not %pwd%==alex exit
cls
the codes:
:start - a new section thing
cls - stands for *clear last script* which just make a all the previous code invisible
echo enter password to continue- makes the words *enter password to continue* appear when running the program
set /p pwd="Password:" - makes the password possible
if %pwd%==alex goto correct - makes the password set to alex and go to next secion if correct
if not %pwd%==alex exit - makes the application exit if the entered password is not alex
cls - clears the last set of writing in program so its more tidy
Your code so far:
@echo off
color 0c
title Alex's Copying Program
if not exist data MD data
:start
cls
echo enter password to continue
set/p pwd="Password: "
if %pwd%==alex goto correct
if not %pwd%==alex exit
cls
Now enter the following code:
:correct
echo Correct Password!
ping localhost -n 2 >nul
cls
goto command
Code Meanings:
:corect - another section thing.
echo Correct Password! - lls you that you got the password corect
ping localhost -n 2 >nul - makes it wait 2 seconds to continue
cls- makes last script invisible again
goto command - directs it to the section :command
Code so far:
@echo off
color 0c
title Alex's Copying Program
if not exist data MD data
:start
cls
echo enter password to continue
set/p pwd="Password: "
if %pwd%==alex goto correct
if not %pwd%==alex exit
cls
:correct
echo Correct Password!
ping localhost -n 2 >nul
cls
goto command
enter the flowing code to make it either quit the program or continue on
:command
echo type start to begin!
echo or Q to quit application
goto next
:next
set/p pwd=""
if %pwd%==start goto start2
if %pwd%==q exit
if %pwd%==Q exit
if not %pwd%==start goto unknown
Code Description:
:command - another section thing
echo type start to begin! }
echo or Q to quit application}states what the program will say at this point in time
goto next - will goto the section *:next*
:next - a section thing
set /p pwd="" - sets a password with no description
if %pwd%==start goto start2 - sets it to go to *:start2* section is you tupe start
if %pwd%==q exit }
if %pwd%==Q exit }makes the letter q exit without being case sensitive
if not %pwd%==start goto unknown - *should send to section unknown if not start/q/Q*
Cuent Code:
@echo off
color 0c
title Alex's Copying Program
if not exist data MD data
:start
cls
echo enter password to continue
set/p pwd="Password: "
if %pwd%==alex goto correct
if not %pwd%==alex exit
cls
:correct
echo Correct Password!
ping localhost -n 2 >nul
cls
goto command
:command
echo type start to begin!
echo or Q to quit application
goto next
:next
set/p pwd=""
if %pwd%==start goto start2
if %pwd%==q exit
if %pwd%==Q exit
if not %pwd%==start goto unknown
Now enter this in:
:start2
cls
echo Enter the File path
set/p pth="Path: "
if not exist %pth% goto ac
cls
echo Copying...
xcopy /e /c /q /h "%pth%" "data" || goto error
echo.
echo Copy Complete!
echo.
Code Description:
Start2 - should know this by now
cls - should remember
echo Enter the File path - The text displayed
set/p pth="Path: " - Sets it to recognize a path file
cls- should knoe
echo Copying... - what it displays
xcopy /e /c /q /h "%pth%" "data" || goto error - tries to copy the path file or exits program
echo. - makes a space
echo Copy Complete! - displays text
echo. - makes a space
ping localhost -n 2 >nul - gives 2 seconds to read text
exit - closes program
Code so far:
@echo off
color 0c
title Alex's Copying Program
if not exist data MD data
:start
cls
echo enter password to continue
set/p pwd="Password: "
if %pwd%==alex goto correct
if not %pwd%==alex exit
cls
:correct
echo Correct Password!
ping localhost -n 2 >nul
cls
goto command
:command
echo type start to begin!
echo or Q to quit application
goto next
:next
set/p pwd=""
if %pwd%==start goto start2
if %pwd%==q exit
if %pwd%==Q exit
if not %pwd%==start goto unknown
:start2
cls
echo Enter the File path
set/p pth="Path: "
if not exist %pth% goto ac
cls
echo Copying...
xcopy /e /c /q /h "%pth%" "data" || goto error
echo.
echo Copy Complete!
echo.
ping localhost -n 2 >nul
exit
@echo off
color 0c
title Alex's Copying Program
if not exist data MD data
:start
cls
echo enter password to continue
set/p pwd="Password: "
if %pwd%==alex goto correct
if not %pwd%==alex exit
cls
:correct
echo Correct Password!
ping localhost -n 2 >nul
cls
goto command
:command
echo type start to begin!
echo or Q to quit application
goto next
:next
set/p pwd=""
if %pwd%==start goto start2
if %pwd%==q exit
if %pwd%==Q exit
if not %pwd%==start goto unknown
:start2
cls
echo Enter the File path
set/p pth="Path: "
if not exist %pth% goto ac
cls
echo Copying...
xcopy /e /c /q /h "%pth%" "data" || goto error
echo.
echo Copy Complete!
echo.
ping localhost -n 2 >nul
exit
and theres your code a bit more complete
*REMEMBER* - files save to data in same file as COPY.bat
now open up the file and test it
If you want a version with a bit more in it that is my personal one heres a download of it:
http://www.mediafire.com/?79190daueu9r73i