Home > Blockchain >  copy movie files from my external drive to my NAS
copy movie files from my external drive to my NAS

Time:03-23

I have a batch which copy movie files from my external drive to my NAS.
Filename looks like this:

Bones S09E18 - Episodename

Batch:

set FOLNAME="Bones\Recordings\"
set FILENAME="Bones "
@echo on
if exist %LPATH%%FILENAME%S09* (if not exist %NASPATH%%FOLNAME%"Season 9" mkdir %NASPATH%%FOLNAME%"Season 9")
copy /Y %LPATH%%FILENAME%S09* %NASPATH%%FOLNAME%"Season 9"

Currently I need to write the code for each Season.
Is it possible to get the season-number and use it as a variable in the code?

CodePudding user response:

set "FOLNAME=Bones\Recordings"
set "FILENAME=Bones"
@echo on
for /L %%b in (0,1,9) do for /L %%c in (0,1,9) do (
 if exist "%LPATH%\%FILENAME% S%%b%%c*" (
  if %%b == 0 (
   mkdir "%NASPATH%\%FOLNAME%\Season %%c" 2>nul
   copy /Y "%LPATH%\%FILENAME% S%%b%%c*" "%NASPATH%\%FOLNAME%\Season %%c"
  ) else (
   mkdir "%NASPATH%\%FOLNAME%\Season %%b%%c" 2>nul
   copy /Y "%LPATH%\%FILENAME% S%%b%%c*" "%NASPATH%\%FOLNAME%\Season %%b%%c"
  )
 )

Tips : Use set "var1=data" for setting values - this avoids problems caused by trailing spaces in a batch file. Don't include the terminal \ in directorynames - counterintuitively, it makes it easier to construct paths.

Simply vary %%b from 0 to 9 using a for/L (well - probably 1 to 2 would suffice) and %%c similarly, and construct the required names, inserting spaces, backslashes and quotes as required.

The 2>nul suppresses error messages (eg. where the directory already exists). Appending >nul to the copy command would suppress the messages reporting the copies. Note 2>nul because that's an errormessage and >nul as that's a normal message.

CodePudding user response:

Have a look at how I have split up the title from the Series and Episodes here.

@echo off
setlocal enabledelayedexpansion
for %%m in (*.mp4) do for %%i in (%%m) do for /f "tokens=1,*delims=SE-" %%a in ('echo %%i ^| findstr /R "S[0-9].E[0-9]."') do (
    set "File=%%m"
    set "remove=!File:*S%           
  • Related