error loading text as variable from file and check it - batch-file

this is some code it suppose to check for adb.exe in a location then if it exist will proceed to code if not will ask user to input location manually and check again if location is right will save the input in file "dontremoveoredit" to use it next time user open the bat file
the problem is if the file is empty or contain path it will crash the bat and close
:: #echo off
If exist "C:\Program Files\ui\adb.exe" (
goto yes
) else (
goto adbexist
)
:yes
set PATH=%PATH%;C:\Program Files\ui"
:: #cd/d "%~dp0"
adb.exe kill-server
adb.exe devices
adb connect localhost:5037
Echo.
Echo.
Echo.
echo Yes Was Executed
Pause>nul
Exit
:no
msg * "Couldn't find The adb.exe in Default Bath"
ping localhost -n 3 >Nul
goto noadbtext
:adbexist
If exist dontremoveoredit (
goto adbexist1
) else (
goto no
)
:adbexist1
set /p var=<dontremoveoredit
if [%var%] == [] (
goto noadbtext
) else (
goto lala
)
:lala
If exist %var%\adb.exe (
set PATH=%PATH%;%var%"
adb.exe kill-server
adb.exe devices
adb connect localhost:5037
goto dns
) else (
msg * "Make Sure You Entered The Right Path To UI"
goto noadbtext
)
:noadbtext
break>"dontremoveoredit"
set /p EmulatorUIBath=Enter Your Emulator's UI folder Path :
If exist "%EmulatorUIBath%\adb.exe" (
#echo %EmulatorUIBath%>> "dontremoveoredit"
goto adbexist2
) else (
msg * "Make Sure You Entered The Right Path To UI"
goto noadbtext
)
:adbexist2
set PATH=%PATH%;%EmulatorUIBath%"
adb.exe kill-server
adb.exe devices
adb connect localhost:5037
echo adb Exist2
Pause>nul
exit

Here you are my laptop is about to die but this should do the needful nicely. :)
Slightly Updated Version I mentioned I woudl post.
#(
SETLOCAL EnableDelayedExpansion
ECHO OFF
SET "_ConfigFilePath=%~0dpn_DO_NOT_REMOVE.dat"
SET "_ADBPath="
SET "_eLvl=0"
SET "ECHO_RW=Call :Echo_Color CF "
SET "ECHO_GB=Call :Echo_Color 20 "
SET "ECHO_AB=Call :Echo_Color B0 "
SET "ECHO_LY=Call :Echo_Color 1E "
SET "ECHO_YL=Call :Echo_Color E1 "
SET "ECHO_YR=Call :Echo_Color EC "
SET "ECHO_RY=Call :Echo_Color CE "
SET "ECHO_BY=Call :Echo_Color 1E "
)
CALL :Main
(
ECHO. Script Completed With ErrorLevel of %_eLvl%
ENDLOCAL
Exit /B %_eLvl%
)
:Echo_Color
ECHO.>"%~2"
FINDStr /A:%~1 /I ".*" "%~2" NUL
DEL /F /Q "%~2" >nul 2>nul
GOTO :EOF
:Main
REM Checing for ADB
CALL :CheckADB
IF /I %_eLvl% NEQ 0 (
ECHO. Error Encountered, Exiting!
) ELSE (
CALL :RunADB
)
PAUSE
GOTO :EOF
:CheckADB
REM Check For ADB Installed in Program Directories
FOR /F "Tokens=1* Delims==" %%A IN ('
SET ProgramFiles
') DO (
FOR /F "tokens=*" %%a IN ('
WHERE /R "%%A" /F "adb.exe" 2^>nul
') DO (
ECHO Found ADB here: "%%~a"
SET "_ADBPath=%%~a"
)
)
REM ECHO.Finished Where Loop
IF NOT DEFINED _ADBPath (
ECHO. ADB Install not Found, checking Config file.
IF EXIST "!_ConfigFilePath!" (
ECHO. Config File Exists checking contents..
FOR /F "Tokens=*" %%A IN ('
TYPE "!_ConfigFilePath!"
') DO (
ECHO. Saved ADB Path Found: "%%~A" in Config file.
IF EXIST "%%~A" (
SET "_ADBPath=%%~A"
) ELSE (
ECHO. Saved ADB Path "%%~A" Does Not Exist! Deleteing Config File.
CALL :Get_ADB_Path_From_User
)
)
) ELSE (
CALL :Get_ADB_Path_From_User
)
)
GOTO :EOF
:Get_ADB_Path_From_User
CLS
REM COLOR CF
ECHO.
COLOR 1E
FOR %%A IN (
"==========================================================="
"= ADB was not detected on your system ="
"==========================================================="
) DO (
REM ECHO.>"%%~A"
REM FINDStr /A:CF /I ".*" "%%~A" NUL
REM DEL /F /Q "%%~A" >nul 2>nul
%ECHO_RY% "%%~A"
)
ECHO.
ECHO.
%ECHO_AB% "Please enter a custom path to ADB below."
ECHO.
ECHO.
SET /P "_TmpADBPath=What Is the Path to your ADB Install? "
CLS
IF NOT EXIST "%_TmpADBPath%" (
%ECHO_RW% "==========================================================="
%ECHO_RW% "== =="
%ECHO_RW% "== Unable to Verify that The path Provided Exists =="
%ECHO_RW% "== =="
%ECHO_RW% "==========================================================="
SET "_eLvl=1"
GOTO :EOF
) ELSE (
COLOR 2F
SET "_ADBPath=%_TmpADBPath%"
ECHO.===========================================================
ECHO. Path Exists:
ECHO.
ECHO. "%_TmpADBPath%"
ECHO.
ECHO. ===========================================================
ECHO.
ECHO.
CHOICE /M "Save this Path for future Use?"
IF /I "%ERRORLEVEL%" EQU "0" (
ECHO.%_TmpADBPath%>"%_ConfigFilePath%"
ECHO.
ECHO. Saved to: "%_ConfigFilePath%"
) ELSE (
ECHO.
ECHO. Okay, Will only use it temporarily.
)
COLOR
)
GOTO :EOF
:RunADB
"%_ADBPath%" kill-server
"%_ADBPath%" devices
"%_ADBPath%" connect localhost:5037
Echo.
Echo.
Echo.
Echo.Yes Was Executed
Pause>nul
Exit

Related

Changing multiple folder icons by dropping folder as input to a batch script

I have a batch script which is used to change a folder's icon.
If [%1] == [] goto :eof
ECHO [.ShellClassInfo] >%1\desktop.in
ECHO IconResource=Example.ico,0 >>%1\desktop.in
move %1\desktop.in %1\desktop.ini
attrib +S +H %1\desktop.ini
attrib +R %1
The problem is that currently the batch file only accepts one folder dropped onto it.
Is there a way for it to accept multiple dropped folders?
if you drop more than one folder, they are received. %1 is just the first of them. Next would be %2 etc. There is a shift command, which shifts the parameters to the left (%1 is discarded, %2 becomes the new %1 etc.):
#echo off
:loop
if "%~1"=="" pause & goto :eof
echo %~1
shift
goto :loop
Notes: use doublequoutes instead of [ and ] to correctly process folders with spaces (and avoid syntax errors with the if command.
use %~1 to remove any surrounding quotes (will be added automatically, if the folder name contains space(s).
There is a line length limitation of about 8200 chars. If you drop too many folders (exceeding the character limit), it will be cut off.
You can try something like that :
#echo off
Color 0A & Mode 75,3
set "ScriptName=%~nx0"
Title Drag and Drop a folder or multi folders over "%ScriptName%"
if "%~1"=="" goto error
:loop
set "$Folder=" & pushd "%~1" 2>nul && ( popd & set "$Folder=%~1"
) || (
set "$Folder=" && echo "%~1" is not a folder & pause
)
If Defined $Folder Call :WriteDesktopIni %$Folder%
shift
if not "%~1"=="" goto loop
echo(
echo End of the script "%ScriptName%"
Timeout /T 3 /nobreak>nul & Exit
::***************************************************************************
:WriteDesktopIni [Folder]
if exist "%~1\desktop.ini" ( attrib -h -s -a "%~1\desktop.ini" >nul 2>&1 )
(
ECHO [.ShellClassInfo]
ECHO IconResource=%systemroot%\system32\shell32.dll,47
)>"%~1\desktop.ini"
attrib +S +H +A "%~1\desktop.ini"
attrib +R "%~1"
goto :eof
::***************************************************************************
:Error
echo(
echo You should drag and drop a folder or multi folders over "%ScriptName%"
Timeout /T 3 /nobreak>nul & exit
::***************************************************************************
Edit : CustomIconFolder.bat
In this script, you can select a folder or multi folders and your custom icon by drag and drop over the script
#echo off & Setlocal EnableDelayedExpansion
Color 0A & Mode 78,5
set "ScriptName=%~nx0"
set /a "count=0"
Title Drag and Drop a folder or multi folders over "%ScriptName%"
if "%~1"=="" goto error
for %%a in (%*) do (
set /a "count+=1"
set "$Folder=" & pushd "%%~a" 2>nul && ( popd & set "$Folder[!count!]=%%~a"
) || (
set "$Folder="
Setlocal DisableDelayedExpansion
color 0C & echo(
echo "%%~a"
echo ====^> is not a folder !
echo Exiting the script . . .
endlocal
Timeout /T 3 /nobreak>nul & exit
)
)
Rem Dispaly selected folders
Mode 75,10
Setlocal EnableDelayedExpansion
for /L %%i in (1,1,%count%) do (
If [%count%] EQU [1] (
echo You have chosen this folder :
echo [%%i] - "!$Folder[%%i]!"
) else (
echo [%%i] - "!$Folder[%%i]!"
)
)
Timeout /T 2 /nobreak>nul
Mode 78,8 & Cls & echo(
echo Please drag and drop your custom icon to be set to your folder over here
echo and press enter...
echo(
echo Or just write the whole path and press enter ...
Set /p "Icon="
If [!Icon!] EQU [] (
cls & echo(
echo The selected icon is : "%systemroot%\system32\shell32.dll,47"
Timeout /T 3 /nobreak>nul
for /L %%i in (1,1,%count%) do (
echo !$Folder[%%i]!
Call :WriteDesktopIni !$Folder[%%i]! "%systemroot%\system32\shell32.dll,47"
)
) Else (
for %%a in (!Icon!) do ( set "Icon_Name=%%~nxa" & set "Ext=%%~xa" )
If /I [!Ext!] EQU [.ICO] (
cls & echo(
echo The selected icon is : "!Icon_Name!"
echo From this path : !Icon!
Timeout /T 3 /nobreak>nul
for /L %%i in (1,1,%count%) do (
echo "!$Folder[%%i]!"
Copy /y !Icon! "!$Folder[%%i]!\!Icon_Name!">nul 2>&1
Attrib +H "!$Folder[%%i]!\!Icon_Name!">nul 2>&1
Call :WriteDesktopIni !$Folder[%%i]! "!Icon_Name!"
)
) else (
Cls & Color 0C & echo(
echo The extension : [*!Ext!] is not allowed
Timeout /T 3 /nobreak>nul
)
)
cls
echo(
echo End of the script "%ScriptName%"
Timeout /T 2 /nobreak>nul & Exit
::***************************************************************************
:WriteDesktopIni [Folder] [Icon]
if exist "%~1\desktop.ini" ( attrib -h -s -a "%~1\desktop.ini" >nul 2>&1 )
(
ECHO [.ShellClassInfo]
ECHO IconResource=%~2
)>"%~1\desktop.ini"
attrib +S +H +A "%~1\desktop.ini">nul 2>&1
attrib +R %~1>nul 2>&1
goto :eof
::***************************************************************************
:Error
Mode 86,10 & color 0B
echo( & echo(
echo You should drag and drop a folder or multi folders over "%ScriptName%"
echo(
echo Or Usage in command line like this syntax :
echo(
echo %~nx0 "FolderPath1" "FolderPath2" "FolderPath3" "FolderPath4"
Timeout /T 10 /nobreak>nul & exit
::***************************************************************************

after compiling a batch file to exe it stops working

I'm writing a small folder locking software. Recently a masking function was integrated, so that the password input is masked. When in a bat file the program works perfectly, however after compiling the program stops working. The problem ,I think, lies in the "masking" code, as it starts an endless loop and masks every input, even the "Enter" stroke, thus preventing the program from further executing. I even tried iexpress, but it also gives an Error, namely:
Error creating process Command.com/c
C:\Users...\AppData\Local\Temp\IXP000.TMP\Folder~1.BAT
Can someone please double check my code and tell me what is wrong, as I am still learning and could not figure out how to fix it.
Thanks in advance.
#Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
mode con cols=80 lines=25
color 5F
title Folder Locker by KBKOZLEV
:SETPASS
set "tipp="
set "password="
if exist "password.txt" (
set /p password=<password.txt
attrib +h +s "password.txt"
)
if exist "tipp.txt" (
set /p tipp=<tipp.txt
attrib +h +s "tipp.txt"
)
:START
if exist "Locked" goto :OPEN
if exist "Unlocked" goto :LOCK
if not exist "Unlocked" goto :MDLOCKER
:LOCK
ren "Unlocked" "Locked"
attrib +h +s "Locked"
echo(
echo Folder locked.
CHOICE /C X /T 1 /D X > nul
goto :END
exit
:MDLOCKER
md "Unlocked"
echo>password.txt 1234
echo>tipp.txt 1234
attrib +h +s "password.txt"
attrib +h +s "tipp.txt"
cls
echo(
echo Private folder created successfully.
CHOICE /C X /T 1 /D X > nul
goto :END
:OPEN
color 2F
cls
echo ********************************************************************************
echo Folder Locker by KBKOZLEV v.01
echo.
echo ********************************************************************************
echo ---- Enter password to unlock folder, or enter "new" to set a new password. ----
echo --------------------------------------------------------------------------------
echo.
echo Password tipp: %tipp%
echo(
set "pass="
rem set /p "pass=Password: "
Set /P "=Password:" < Nul
Call :PasswordInput pass
if /i "%pass%"=="new" goto :NEWPASS
if "%pass%"=="%password%" (
attrib -h -s "Locked"
ren "Locked" "Unlocked"
echo(
echo Folder unlocked successfully.
goto :END
)
goto :FAIL
:FAIL
color 4F
cls
echo(
echo Invalid password, please try again.
CHOICE /C X /T 1 /D X > nul
cls
goto :OPEN
:NEWPASS
color 8F
cls
echo(
set "oldpass="
rem set /p "oldpass=Old password: "
Set /P "=Old Password:" < Nul
Call :PasswordInput oldpass
if not "%oldpass%"=="%password%" goto :FAIL
:ENTERNEW
color 8F
cls
echo(
set "newpass=""
rem set /p "newpass=New password: "
Set /P "=New Password:" < Nul
Call :PasswordInput newpass
set newpass=%newpass:"=%
if "%newpass%"=="" (
echo(
echo Invalid new password, please enter new password again.
CHOICE /C X /T 1 /D X > nul
goto :ENTERNEW
)
if exist "password.txt" attrib -h -s "password.txt"
echo>password.txt %newpass%
echo(
set "passtipp=""
set /p "passtipp=New tipp: "
set passtipp=%passtipp:"=%
if exist "tipp.txt" attrib -h -s "tipp.txt"
if not "%passtipp%"=="" (
echo>tipp.txt %passtipp%
) else (
del "tipp.txt"
)
goto :SETPASS
:END
color
EndLocal
Goto :Eof
:PasswordInput
::Author: Carlos Montiers Aguilera
::Last updated: 20150401. Created: 20150401.
::Set in variable Line a input password
::
::Update 20150503: http://stackoverflow.com/users/3439404/josefz?tab=profile
::Changes made in next lines:
:: SetLocal EnableDelayedExpansion
:: If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
::Usage:
:: Call :PasswordInput variableName
::where variableName is a name of output variable (by reference call)
::
SetLocal EnableDelayedExpansion
For /F skip^=1^ delims^=^ eol^= %%# in (
'"Echo(|Replace.exe "%~f0" . /U /W"') Do Set "CR=%%#"
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do Set "BS=%%#"
Set "Line="
:_PasswordInput_Kbd
Set "CHR=" & For /F skip^=1^ delims^=^ eol^= %%# in (
'Replace.exe "%~f0" . /U /W') Do Set "CHR=%%#"
If !CHR!==!CR! Echo(&EndLocal&set "%1=%Line%"&Goto :Eof
If !CHR!==!BS! (If Defined Line (Set /P "=!BS! !BS!" <Nul
Set "Line=!Line:~0,-1!"
)
) Else (Set /P "=*" <Nul
If !CHR!==! (Set "Line=!Line!^!"
) Else Set "Line=!Line!!CHR!"
)
Goto :_PasswordInput_Kbd
You are executing the 16 bit command.com (only in Win 32) not the 32 or 64 bit cmd.exe. It doesn't suport brackets, long filenames, or set /p.
It also doesn't support long file names.

Only use first word of input batch file

I am making a program that needs to run the commands that users put in.
If the command doesn't exist it opens an error.
:cmd
set /p cmd="Command:"
if not exist %cmd% goto nocommand
%cmd%
:noCommand
echo Error, command doesn't exist..
goto cmd
But if I type "echo text" it says text isn't a command. I need it to only read the first word.
Checks if its is possible to execute the command as an internal,from given path or from %PATH%. It uses also solution from dbenham from here : Check if command is internal in CMD
#echo off
:cmd
set /p "cmd=Command:"
for /f "tokens=1 delims= " %%a in ("%cmd%") do set "fcmd=%%~na"
setlocal
set "empty=%temp%\empty%random%"
md "%empty%"
pushd "%empty%"
set path=
>nul 2>nul %fcmd% /?
if not errorlevel 9009 (
popd
rd "%empty%"
echo %fcmd% is internal command
endlocal
goto :execute
) else (
popd
rd "%empty%"
endlocal
)
color
for %%# in (%PATHEXT%;"" ) do (
rem echo --%fcmd%%%~#--
if exist %fcmd%%%~# (
echo the command/executable/script will be executed from given location
goto :execute
)
for /f "tokens=1 delims= " %%a in ("%fcmd%%%~#") do (
if "%%~$PATH:a" NEQ "" (
echo the command/executable/script is defined in %%PATH%%
rem
goto :execute
)
)
)
echo command does not exist
exit /b 1
:execute
%cmd%
set /p cmd="Command:"
for /f "tokens=1" %%i in ("%cmd%") do set firstword=%%i
echo %firstword%

Directory traversal and file selection with .bat

I am trying to write a .bat file that allows me to traverse through directories (up or down) and let me select a file from the current directory, passing that filename out at the end of the routine. Ideally, it would handle if it is at the root of a drive (i.e. C:) or that there are no more sub directories.
(If there are more elegant ways of doing what I am asking, please feel free to suggest them!)
#echo off
setlocal enabledelayedexpansion
set FVAR=
:start
::-------------------------------------------------------
:: LIST - Lists all files in the current folder
::-------------------------------------------------------
:LIST
echo.
if exist . echo ^<DIR^> .
if exist .. echo ^<DIR^> ..
for /f "tokens=* delims=" %%a in ('dir /b /ad') do (
echo ^<DIR^> %%a
)
for /f "tokens=* delims=" %%a in ('dir /b /a-d') do (
echo %%a
)
::-------------------------------------------------------
:: INPUT - Requests filename as input from user
::-------------------------------------------------------
:INPUT
echo.
set /p FVAR="Choose your file [HINT: hit <TAB> to cycle the current folder contents]: "
echo.
echo %FVAR%
if not defined FVAR (goto TRYAGAIN)
set FVARFLAG1=0
set FVARFLAG2=0
set FVARFLAG=%FVARFLAG1%%FVARFLAG2%
echo %FVARFLAG%
if exist %FVAR%\ set "%FVARFLAG1%"=="1"
if exist %FVAR% set "%FVARFLAG2%"=="1"
set FVARFLAG=%FVARFLAG1%%FVARFLAG2%
echo %FVARFLAG%
if "%FVARFLAG%"=="00" goto TRYAGAIN
if "%FVARFLAG%"=="01" goto FILE
if "%FVARFLAG%"=="10" goto DIR
if "%FVARFLAG%"=="11" goto TRYAGAIN
goto TRYAGAIN
:DIR
if exist %FVAR%\ (
echo Successfully set dir name!
goto END
)
goto TRYAGAIN
:FILE
if exist %FVAR% (
echo Successfully set file name!
goto END
)
goto TRYAGAIN
rem if /i "%option:"=%"=="Y" goto YES //This line left in for future use
rem if /i "%option:"=%"=="N" goto NO //This line left in for future use
goto END
::-------------------------------------------------------
:: TRYAGAIN - Returns user to input menu on invalid entry
::-------------------------------------------------------
:TRYAGAIN
echo ------------------------------
echo Invalid selection...try again
echo ------------------------------
goto INPUT
:END
goto :EOF
I like this application! The use of arrays allows you to write simpler and more powerful code. This is my version:
#echo off
setlocal EnableDelayedExpansion
rem Select a file browsing a directory tree
rem Antonio Perez Ayala
set pageSize=30
rem Load current directory contents
:ProcessThisDir
for /F "delims==" %%a in ('set name[ 2^>NUL') do set "%%a="
set numNames=0
for /D %%a in (*) do (
set /A numNames+=1
set "name[!numNames!]=<DIR> %%a"
)
for %%a in (*.*) do (
set /A numNames+=1
set "name[!numNames!]= %%a"
)
rem Show directory contents, one page at a time
set start=1
:ShowPage
if %start% equ 1 (
set "less="
) else (
set "less=-=Previous page, "
)
set /A end=start+pageSize-1
if %end% gtr %numNames% (
set end=%numNames%
set "more="
) else (
set "more=+=Next page, "
)
cls
echo Directory: %CD%
echo/
for /L %%i in (%start%,1,%end%) do echo %%i- !name[%%i]!
echo/
:GetOption
set "option="
set /P "option=Enter desired item (%less%%more%Nothing=..): "
if not defined option (
cd ..
goto ProcessThisDir
) else if "%option%" equ "-" (
set /A start-=pageSize
if !start! lss 1 set start=1
goto ShowPage
) else if "%option%" equ "+" (
if defined more set /A start+=pageSize
goto ShowPage
) else if not defined name[%option%] (
goto GetOption
) else if "!name[%option%]:~0,5!" equ "<DIR>" (
cd "!name[%option%]:~8!"
goto ProcessThisDir
)
rem Return selected file
cls
for %%a in ("!name[%option%]:~8!") do set "result=%%~Fa"
echo Result="%result%"

Batch-Scripting permission changes for a copied file and subroutine possibilities?

I am trying to achieve the following:
For every file in the source folder %1; Display it's details, ask the user whether the file should be copied and if the user answers "no" display a message "skipped", otherwise copy the file to the target folder %2, set the copy's permissions to "read-only", and display a message.
This is what I have managed so far but the last part I have had no luck understanding.
#echo off
rem if the source folder does not exist, display a message and exit
if exist "%1%" (
echo .
) else (
echo Source folder doesn't exist.
exit /b
)
if exist "%2%" (
echo Directory exists
) else (
md %2
echo Directory Created
)
FOR /F "DELIMS==" %%f in ('DIR "%1" /B') DO (
ECHO %%f
set p = NULL
SET /p p="Copy(y/n)?"
IF "%p%" == "y" (
COPY "%1\%%f" "%2"
ECHO Copied %%f to %2
) ELSE (
ECHO "%%f" Skipped
)
)
Is this possible? And if it is can it be done with a subroutine for the iteration process (copying and setting permissions)?
I made a batch script to do this operation
#echo off
::This batch file works with arguments or no
::copysec "sourcefolder" "destination folder"
if not "%1" == "" (
set "source=%1") else (
set /p "source=Source folder: ")
if not "%2" == "" (
set "destination=%2") else (
set /p "destination=Destination folder: ")
if not exist "%destination%" (
echo/Destination folder %source% not found&pause>nul&exit/b)
if exist "%source%" (
pushd "%source%") else (
echo/Source folder %source% not found&pause>nul&exit/b)
set /a count=0
for %%f in (*.*) do (
CALL:PROCESS "%%f")
echo/Finished. %count% files copied
popd&exit/b
:PROCESS file
cls
if "%~x1" == "" (exit/b)
echo/Full path: %~f1&echo/Disk: %~d1
echo/Name: %~n1&echo/Extension: %~x1
echo/Attributes: %~a1&echo/Time %~t1
echo/Size: %~z1 bytes&echo/
set /p "choice=Do you want to copy %1? [Y/N] "
if /i "%choice%" == "y" (
Goto Y)
echo/Skipped&timeout 2 1>nul&exit/b
:Y
copy "%~1" "%destination%\%~1" >nul || GOTO FAIL
attrib +R "%destination%\%~1" >nul || GOTO FAIL
:NEXT
set /a count=count+1
echo/Precess sucefull!&timeout 2 1>nul&exit/b
:FAIL
echo/Failed to copy %~1
pause>nul
exit/b
Well if you want to copy all files of all subfolders, you can use for /r
save it as copysec.bat.

Resources