Help With Hopefully Simple Batch Script

Soldato
Joined
25 Jul 2006
Posts
3,526
Location
Taunton
Hi All,

Just looking for some help with a batch script to move some files around.

Basically I have a Camera that sends .264 files to a NAS drive, I then have a little computer that converts those into .mp4 so they are easily playable from multiple devices. The problem comes with the file structure that they are so for example currently they are like this:

Code:
Z:\CCTV\<Date>\Record\<filename>.mp4

All I would like to do after they have been converted into .mp4 is also move them into the parent directory so it shows like:
Code:
Z:\CCTV\<date>\<filename>.mp4

The reason I specifically refer to the .mp4 is because I want it to ignore .264 files as it sends them to the "Record" folder and that's where Handbrake finds the files to convert... and I can't change the Camera's preset file structure.

Not sure how I can adapt the script, I have this script

Code:
for /R Z:\CCTV\ %%F in (*.264) do (
    "..\HandBrakeCLI.exe" -i "%%~fF" -o "%%~dpF%%~nF.mp4"
    if exist "%%~dpF%%~nF.mp4" (
        del "%%~fF"
    )
)

Could this be adapted to move the files up? I have looked at so many different scripts and can't really get my head round this whole "%%~dpf" jazz, I understand that they link to variables like the drive name and file path but can't figure out how to adapt it to what I need.

The closest I got was:
Code:
forfiles /P Z:\CCTV /s /m *.mp4 /c "cmd /c move @file .."

The obvious problem with this was that every time the script was run it was moving the files up and up, which isn't what I want. I almost need it to run some sort of additional script like "If folder = record process, else ignore" If you catch my drift?

The script to search for the files to be converted is run every 10 minutes so that's I can't afford for it to be as the last. Any suggestions or solutions would be greatly appreciated!!
 
Thank you @visibleman I'll try and use that in my test folders and see how I get on.

And @Bug One I could rename them but I'm quite happy how they are named, I simply want to move them up one level so they are directly in the date named folder. This probably is doable from the output if I could figure out how to do it!

Also .264 is not natively playable on my pc or Android phone where I view them.
 
Code:
for /f "delims=" %%D in ('dir /a:d /b Z:\CCTV') do forfiles /P %%~fD\Record /s /m *.mp4 /c "cmd /c move @file .."

So when I try and run that it changes the directory to
Code:
C:\user\richa\<date>\record
And then exits saying error: directory name is invalid.
Does this have something to do with Z: being a mapped network drive?

Any further help would be appreciated
 
That last one worked perfectly, thank you so much!

Needless to say I would never have got there as I only got the main conversion script working through trial and error and ripping other scripts together, but I was getting nowhere with this one.

I've set it to run at the end of the conversion script through task scheduler so gonna let it do its thing and keep my fingers crossed, but it worked perfectly with my test folders.
 
Maybe a slight added complication...

Task scheduler for some reason doesn't like the mapped network drive side of things so I have to use the UNC path name but the for function doesn't seem to like that.

Comes back with "ERROR: UNC path (\\machine\share) are not supported."
 
I do remember trying something like that with one of the scripts that I did trial trying to get this working previously.

I'll find it again and give it a go.
 
@visibleman got it working with net use commands. Ironically I also used the same net use to correct another script that I didn't even realise wasn't working correctly until I tested it and it didn't do anything.

Thank you for the script and the help!
 
Back
Top Bottom