Last active
June 9, 2020 04:23
-
-
Save blueal/bed38c55ea1dd086fcb6f277d7a456a6 to your computer and use it in GitHub Desktop.
Batch script to copy folders or files based on Media Category
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 | |
REM Script to copy completed torrent files to there respective folders | |
REM Parameter 1: Full file path. Sometimes it's a directory, sometimes it's just a file. | |
REM Parameter 2: Category of file. The copy location will vary based on this. The deafault is DO NOTHING. | |
REM PLEASE NOTE: THIS HAS NOT BEEN SANITIZED: DO NOT COPY YOUR ROOT DIRECTORY BY ACCIDENT | |
REM ROBOCOPY WILL OVERWRITE EVERYTHING IF THERE'S EXISTING CONTENT WITH THE SAME NAME! BE CAREFUL! | |
echo [101;93mROBOCOPY WILL OVERWRITE EVERYTHING | |
echo IF THERE'S EXISTING CONTENT, IT WILL BE OVERWRITTEN | |
echo YOU'VE BEEN WARNED! | |
echo. | |
echo DANGER DANGER DANGER | |
echo THIS PROGRAM WILL RUN ANYTHING YOU PASS INTO IT, ONLY PASS IN FULLY QUALIFIED FILENAMES AND EXPECTED INPUT | |
echo INPUTS ARE NOT SANITIZED, USE WITH EXTREME CAUTION! | |
echo DONT BLAME ME WHEN YOU ACCIDENTLY COPY YOUR ENTIRE C:/ DRIVE[0m | |
echo. | |
setlocal enabledelayedexpansion | |
SET singleLogFile=D:\Logs\CopyLog.txt | |
SET masterLogFile=D:\Logs\MasterCopyLog.txt | |
SET moviePath=D:\Videos\Movies\ | |
SET TVPath=D:\Videos\TV\ | |
SET musicPath=D:\Music\ | |
SET EXITLINE=~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
echo. > %singleLogFile% | |
echo PATH: %1 | |
echo Category: "%2" | |
echo PATH: %1 >> %singleLogFile% | |
echo Category: "%2" >> %singleLogFile% | |
pause REM REMOVE THIS PAUSE IF YOUR READY TO TRUST ME | |
if %2 == Movies ( | |
echo This is a Movie, I'll put it in the movie folder: %moviePath% | |
echo This is a Movie, I'll put it in the movie folder: %moviePath% >> %singleLogFile% | |
SET "copyPath=%moviePath%%~n1" | |
) else if %2 == TV ( | |
echo This is a TV Show, I'll put it in the TV folder: %TVPath% | |
echo This is a TV Show, I'll put it in the TV folder: %TVPath% >> %singleLogFile% | |
SET "copyPath=%TVPath%%~n1" | |
) else if %2 == Music ( | |
echo This is Music, I'll put it in the Music folder: %musicPath% | |
echo This is Music, I'll put it in the Music folder: %musicPath% >> %singleLogFile% | |
SET "copyPath=%musicPath%%~n1" | |
) else ( | |
echo An item with an invalid category came through here: | |
echo PATH: %1 | |
echo Category %2 | |
echo An item with an invalid category came through here: >> %singleLogFile% | |
echo PATH: %1 >> %singleLogFile% | |
echo Category "%2" >> %singleLogFile% | |
GOTO:exitScript | |
) | |
echo I will now copy this item %1 | |
for /f "tokens=1,2 delims=d" %%A in ("-%~a1") do ( | |
if "%%B" neq "" ( | |
echo %1 is a folder | |
echo Copying the folder: %1 >> %singleLogFile% | |
robocopy "%~f1" "%copyPath%" /E /A-:SH /R:15 /NP /ETA /LOG:%singleLogFile% /TEE | |
) else if "%%A" neq "-" ( | |
echo %1 is a file | |
echo Copying the file: %1 >> %singleLogFile% | |
echo "%~dp1" is the parent directory >> %singleLogFile% | |
echo "%~nx1" is the file name >> %singleLogFile% | |
robocopy %~dp1 "%copyPath%" "%~nx1" /A-:SH /R:15 /NP /ETA /LOG:%singleLogFile% /TEE | |
) else ( | |
echo %1 does not exist | |
echo Attempted to copy a nonexstant file: %1 >> %singleLogFile% | |
GOTO :exitScript | |
) | |
) | |
echo The item "%~nx1" was copied with Exit Code: %errorlevel% >> %singleLogFile% | |
attrib -h -s "%copyPath%" | |
:exitScript | |
type %singleLogFile% >> %masterLogFile% | |
echo %EXITLINE% >> %masterLogFile% | |
GOTO:EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment