-1

new here and hoping this is an easy question. I have very little background in programming and scripting but I've got the basics working so far and I'm stuck.

The logic of what I'm trying to accomplish with the parts marked I need help with;

  1. scan my IP cam folder for the largest file
  2. need help check that file against a list of already processed files
  3. move that file to a temp Working dir on a PC with a good CPU and SSD
  4. run HandBrake on it to compress it
  5. move the finished file back to its original location
  6. delete the original from the temp working directory
  7. write its file name to Processed.txt
  8. need help Loop the whole thing to run endlessly

Right now it's working perfectly to scan and find the largest file and send it for processing and move it back. What I want to add is a check of the Processed.txt file during the size scan as very often the largest files still end up to be the largest even after compression (so it gets stuck on the same one). Basically I want to be able to endlessly scan for the largest unprocessed file and compress them one by one. (I have THOUSANDS so typical batch processing wont really work)

I was trying to work out how to get the findstr into the for\do loop but I'm totally lost on that. My thinking is to take the current %name% variable, run it though findstr on the Processed.txt file and if it matches move on, if not make that the current largest file.

here's what I have working so far that I've managed to piece together from other posts;

SETLOCAL EnableDelayedExpansion
set tes=0
set name=
set path=

for /r D:\Cameras %%h in (*.*) do (
IF !tes! LSS %%~zh (
SET tes=%%~zh
SET name=%%~nh
SET path=%%~ph
SET ext=%%~xh
)
)

move "d:%path%%name%%ext%" "d:\Working\"

HandBrakeCLI -i "d:\Working\%name%%ext%" -o "c:\Completed\%name%.mp4" -O -e x264 -q 23 -B 128 -w 720 -l 480 --auto-anamorphic

move "c:\Completed\%name%.mp4" "d:%path%%name%.mp4"
del "d:\Working\%name%%ext%"
echo !name! >> Processed.txt

Thanks in advance, and any and all help is greatly appreciated.

*****EDIT UPDATE***** So i couldn't get the below to work but it took me a new direction. Right now the below seems to be pretty close to working but the second FOR DO IF seems to process outside of the main loop. Maybe someone could help fix that because that is the logic that i think will work for me.

i rem out the stuff i know is working just to test if itll scan, enter the file name, then skip it next time around for testing.

rem :start
SETLOCAL EnableDelayedExpansion
set tes=0
set name=
set path=
set found=false

for /r d:\Cameras %%h in (*.*) do ( 
rem CALL :checkprocessed %%h
for /f %%x in (d:\Processed.txt) do (
IF "%%~nh" NEQ "%%~x" IF !tes! LSS %%~zh (
echo !tes! %%~zh %found% >> ifcheck.txt 
SET tes=%%~zh
SET name=%%~nh
SET path=%%~ph
SET ext=%%~xh
)
)
)

rem move "d:%path%%name%%ext%" "d:\Working\"
rem HandBrakeCLI -i "d:\Working\%name%%ext%" -o "c:\Completed\%name%.mp4" -O -e x264 -q 23 -B 128 -w 720 -l 480 --auto-anamorphic
rem move "c:\Completed\%name%.mp4" "d:%path%%name%.mp4"
rem del "d:\Working\%name%%ext%"
echo !name! >> Processed.txt
rem goto :start


rem :checkprocessed
rem SET found=false
rem for /f %%x in (d:\Processed.txt) do IF "%%~nh" EQU "%%~x" (SET found=true & echo !found! >> found.txt & exit /b 0)
rem exit /b 0
Solonor
  • 1
  • 2
  • Your `For` loop is scanning every file recursively, but the variables are being used outside of the loop, which means they'll only work against the very last file output in the loop. You need to move your commands into the loop and use `!`'s instead of `%`'s for the variable names. – Compo Oct 14 '18 at 22:44
  • Or just call a subroutine from the loop body and do all the work in the subroutine using the passed-in parameter(s). – jwdonahue Oct 14 '18 at 22:46
  • 1
    You are overwriting the SYSTEM variable PATH. I would highly advise you not do that – Squashman Oct 14 '18 at 23:02
  • Why do you move the files from c:\completed back to the original directory? – jwdonahue Oct 14 '18 at 23:45
  • Hi All, thanks for the responses so far. Right now this is looping though all the files and giving me the info on the very largest one. which is what i want, i want it to find the biggest file, run it through hand break, then put it back where it was compressed as I have other applications, sorting, etc, that read it from there. Then i want it to grab the next largest file and do that one, and so on one by one. Basically I'm trying to be as non-disruptive as possible to the existing videos while moving them to a MUCH more powerful computer to run handbrake on. – Solonor Oct 15 '18 at 17:07
  • Where-ever the script is running, that's where handbrake is running. – jwdonahue Oct 16 '18 at 00:37
  • Loop bodies are like that. They always show up in the spew after the closing parenthesis. Debugging scripts with multi-line code blocks is major pain. I avoid them at all cost. – jwdonahue Oct 18 '18 at 00:01
  • BTW: User goto :EOF to go to the end of the file and you don't have to add an :End label. – jwdonahue Oct 18 '18 at 00:36
  • I am withdrawing for now. Got close, but there's a mystery to solve. – jwdonahue Oct 18 '18 at 03:35

1 Answers1

0

First I want to thank @jwdonahue for all the help and time spent on this. Going back and forth with ideas, I was able to get a script to work perfectly! Below is the working script if anyone needs it. I fixed the path as well from another users comment. Thanks everyone for all the help!

:start
SETLOCAL EnableDelayedExpansion
set tes=0
set name=
set _path=
set ext=
set _found=false

for /r d:\Cameras %%h in (*.*) do (
for /f %%x in (d:\Processed.txt) do ( IF "%%~nh" EQU "%%~x" ( set _found=true) )
IF !_found! EQU false IF !tes! LSS %%~zh (
SET tes=%%~zh
SET name=%%~nh
SET _path=%%~ph
SET ext=%%~xh
)
set _found=false
)


move "d:%_path%%name%%ext%" "d:\Working\"
HandBrakeCLI -i "d:\Working\%name%%ext%" -o "c:\Completed\%name%.mp4" -O -e x264 -q 23 -B 128 -w 720 -l 480 --auto-anamorphic
move "c:\Completed\%name%.mp4" "d:%_path%%name%.mp4"
echo !name! >> Processed.txt
echo !_path!,!name!!ext!,!tes! >> OrgSize.log
del "d:\Working\%name%%ext%"
goto :start
Solonor
  • 1
  • 2