How can I use a script to use this mp4box[GPAC] command on multiple files in a directory (parsing one file at a time ) [duplicate] - shell

This question already has answers here:
Batch file to execute all files in a folder
(6 answers)
Execute command on all files in a directory
(10 answers)
Closed 14 days ago.
mp4box -splits 3900000 1.mp4 using mp4box
Possible Solution Found : #echo off for /f "delims=" %%i in ('dir /b /s /a-d "*.mp4"') do ( MP4Box.exe -splits 3900000 "%%i" )

Related

How to access the individual items in a variable in Windows Batch? [duplicate]

This question already has answers here:
Arrays, linked lists and other data structures in cmd.exe (batch) script
(11 answers)
How to loop through comma separated string in batch?
(4 answers)
Closed 2 years ago.
I have this list in batch:
set list=12,34,56
echo %list%
How can I get the list to print only 34?
To print the second number 34:
for /f "tokens=2 delims=," %%a in ("%list%") do #echo %%a
To print all 3 numbers 12 34 56:
for /f "tokens=1-3 delims=," %%a in ("%list%") do #echo %%a %%b %%c
The double percents in %%a are required in a batch file. At the command prompt, use just %a.

Using strings in batch files [duplicate]

This question already has answers here:
What does symbol ^ mean in Batch script?
(4 answers)
Closed 6 years ago.
I have a simple command within my bat file that is causing it to explode, I think it has to do with using a string within the command but I am a bit clueless now.
The command in question is:
for /f %%i in ('dir *.nupkg /b/a-d/od/t:c | findstr "symbols"') do set LAST=%%i
What is the right way of using the "symbols" string in the above line?
I don't understand why you're piping the results through Findstr.
For /F "Delims=" %%A In ('Dir/B/A-D/OD/T:C *symbols*.nupkg') Do Set "LAST=%%A"
If you're not sure as to whether the last file will contain the string symbols in it's name, and that is what you're trying to ascertain, then you could still check that after the loop.
For /F "Delims=" %%A In ('Dir/B/A-D/OD/T:C *.nupkg') Do Set "LAST=%%A"
If "%LAST:symbols=%"=="%LAST%" (Echo= NOT a symbols file) Else (
Echo= WAS a symbols file)

Delete all folders except one [duplicate]

This question already has answers here:
Windows batch script to delete everything in a folder except one
(3 answers)
Closed 6 years ago.
I want to delete all files and folders in my C:\temp except one specific folder (C:\temp\123) which contains a lot of files and subfolders.
I tried with pushd "c:\temp\123" && rd /s /q "c:\temp" but it deletes all subfolders and files in c:\temp\123.
Can any one please help on the above?
You could do it the following way:
pushd "C:\Temp" || exit /B 1
for /D %%D in ("*") do (
if /I not "%%~nxD"=="123" rd /S /Q "%%~D"
)
for %%F in ("*") do (
del "%%~F"
)
popd
This is very similar to this approach: Batch command to delete everything (sub folders and files) from a folder except one file.

Path relative to another in bat file [duplicate]

This question already has answers here:
Batch files: List all files in a directory with relative paths
(6 answers)
Closed 8 years ago.
I am writing a bat file, and one of the commands need a project path and a file path relative to the project.
For example
awesomecommand.exe project=C:\MyProject file="myfiles\file1.fbx"
I am iterating through all files in C:\MyProject (where my .bat file is located):
for /R "%~dp0" %%f in (*.fbx) do (
....
)
and I need to get the %%f path relative to %dp0. So if %%f = C:\MyProject\myfiles\file1.fbx and %~dp0="C:\MyProject", I need the result to be "myfiles\file1.fbx".
How would I do this?
setlocal enabledelayedexpansion
for ... (
set P=%%f
set P=!P:%~dp0=!
echo !P!
)
will remove the startup directory from P. (%~dp0 contains a trailing slash)
xcopy command can be used to retrieve the list of files with relative paths
pushd "%~dp0"
for /f "tokens=1,* delims=\" %%a in ('xcopy "." "%temp%" /s /l ^| find "\"') do (
echo %%b
)
popd
The list of files retrieved in in the format
.\folder\file.ext
.\file.ext
....
The for command delims and tokens handle the removal of the starting characters to leave the format requested

How to find the last directory created in batch [duplicate]

This question already has answers here:
Get last created directory batch command
(2 answers)
Closed 8 years ago.
This is my first question and I'm not very experienced using batch files so hope someone can help.
I want to find the last directory created using a batch file and have tried:
FOR /f "tokens=*" %%A in ('dir "%latestdirectory%" /AD-h /B /o-d') do (set recent=%%A)
but this result keeps returning the oldest directory not the most recent one.
Still trying to pick this up in batch.
FOR /f "delims=" %%A in ('dir "%latestdirectory%" /AD-h /B /od') do (set recent=%%A)
for help enter dir /? at the command line.
To get the last created subdirectory (and not the last modified one if any file or sub-sub-directory added in it), this should work:
FOR /F %%i IN ('dir /a:d /t:c /o-d /b') DO (
SET a=%%i
GOTO :found_last
)
echo No subfolder found
goto :eof
:found_last
echo Most recent subfolder: %a%
set last_subforlder=%a%

Resources