Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem Main use to move entire directory/drive without looking at the data before hand or otherwise reading the data more then needed.
- rem useful for larger drives/folder sizes with many files.
- rem respects access rights (if you can not get there in command-line, or access/read they file it will skip it)
- rem meant to be as light as possible for drives that may not tolerate a lot of data manipulation.
- rem Powershell version in the works, for network access.
- rem must be local drive w/ letter or mapped network drive that is accessible via mapped drive letter.
- rem use of the variable adjustment to avoid multiple inputs that can be referred from a path&Drive letter.
- rem setting variables, and tests for arguments being passed in or not, & checks \? for help
- set FILENAME=DC.bat
- if %1 == \? GOTO HELP
- set SRC=.
- set DEST=.
- set SRC=%1
- set DEST=%2
- set INP=.
- set IFL=.
- set IFLP=.
- if %SRC% == . GOTO NSRC
- if %DEST% == . GOTO NDEST
- GOTO FORM
- rem Starting loop, moving to the correct drive, then moves to the right folder (with assuming it may not always be the root of the drive.
- :START
- %SRC:~0,2%
- cd %SRC%
- for /r %%a in (*.*) do (
- set INP=%DEST%%%~pa
- set IFL=%%a
- set IFLP=%%~nxa
- CALL :ACT
- )
- GOTO FIN
- rem Checks for the matching folder structure, and does it one level at a time, due to the nature of the recursive For loop that calls [ACT], then creates the folder if needed which is followed by a copy.
- :ACT
- IF NOT EXIST "%INP%" MD "%INP%"
- copy /v /y "%IFL%" "%INP%"
- IF EXIST "%INP%%IFLP%" echo "%INP%%IFLP%"
- GOTO FIN
- rem some input cleaning and ensuring that the variables can mesh the paths as needed without error.
- :FORM
- IF %SRC:~-1% == / set SRC=%SRC:~0,-1%\
- IF NOT %SRC:~-1% == \ set SRC=%SRC%\
- IF %DEST:~-1% == / set DEST=%DEST:~0,-1%
- IF %DEST:~-1% == \ set DEST=%DEST:~0,-1%
- GOTO PRIME
- rem Argument checks
- :PRIME
- IF NOT EXIST "%SRC%" GOTO NOSRC
- IF NOT EXIST "%DEST%" GOTO NODEST
- GOTO START
- rem error outputs, and pauses in the following sections, and the help section bellow.
- :NSRC
- echo Source Input required at end.
- pause
- GOTO FIN
- :NDEST
- echo Destination Input Required.
- pause
- GOTO FIN
- :NOSRC
- echo Source Directory does not exist, or incorectly entered
- pause
- GOTO FIN
- :NODEST
- echo Destination Directory does not Exist, or incorrectly entered
- pause
- GOTO FIN
- :HELP
- echo For copying entire Directories with folder structure intact, ignoring 'empty folders'
- echo %FILENAME% [Source] [Destination]
- echo Example %FILENAME% X:\ "F:\Named Folder"
- echo If folders have spaces in the name. use Double Quotes around the whole argument Example "D:\Named Folder"
- :FIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement