Created
February 28, 2015 18:50
-
-
Save anonymous/c984b48176eb154986c2 to your computer and use it in GitHub Desktop.
CopyFiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
TITLE WAIT ! | |
:: ASSIGN THE FILE PATH OF BATCH FILE TO A VARIABLE | |
SET "sourceDir=%CD%" | |
:: GET THE NAME OF THE FOLDER WHICH THE BATCH FILE IS IN | |
FOR %%a IN (.) DO SET currentFolder=%%~na | |
:: GO UP ONE DIRECTORY | |
CD .. | |
:: MAKE A DYNAMIC FOLDER NAME | |
::SET folderName=Copied From %currentFolder% | |
SET "folderName=Copied from %currentFolder%" | |
:: CREATE A FOLDER TO PUT THE COPIED FILES IN | |
:: IF FOLDER ALREADY EXISTS DELETE IT | |
IF EXIST "%folderName%" RMDIR "%folderName%" /S /Q | |
MKDIR "%folderName%" | |
:: ASSIGN DESTINATION FOLDER TO A VARIABLE | |
SET "destinationFolder=%CD%\%folderName%" | |
:: CREATE A LOG FILE IN DESTINATION FOLDER | |
SET "_report=%destinationFolder%\logxcopy.txt" | |
:: CREATE ERROR MESSAGE | |
IF NOT EXIST "%sourceDir%" (ECHO.Could not find %sourceDir% &GoTo:DONE) | |
:: OVERWRITE PREVIOUS LOG | |
>"%_report%" ( | |
echo.%date% - %time% | |
echo.--------------------------------------------------- | |
echo. | |
) | |
:: COPY FILES | |
FOR /F "Delims=" %%! IN ('DIR "%sourceDir%\" /b /s /a-d 2^>NUL') DO ( | |
@ECHO.%%! &( | |
@XCOPY "%%!" "%destinationFolder%\" /i /y /h /f /c >>"%_report%",2>&1) | |
) | |
:DONE | |
TITLE,Done....... | |
ECHO.&PAUSE>NUL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment