Reputation: 327
I want to scan a folder whose path is defined by user input & finally apply ffmpeg to store all media files information into a text file. The following code does not work
@echo off
setLocal EnableDelayedExpansion
set /P "path=Enter folder path: "
dir %path% /B /O:N | findstr ".wmv$ .mpg$ .mkv$ .mpeg$ .mp4$ .avi$" >filename.txt
echo. >info.txt
for /f "tokens=* delims= " %%a in ('type filename.txt') do (
set in=%in%%%a
ffprobe "%path%!in!" 2>>info.txt
)
pause
However if I strip user input as follows the code does work?
@echo off
setLocal EnableDelayedExpansion
::set /P "path=Enter folder path: "
dir d:\Trainers\out\outt\ /B /O:N | findstr ".wmv$ .mpg$ .mkv$ .mpeg$ .mp4$ .avi$" >filename.txt
echo. >info.txt
for /f "tokens=* delims= " %%a in ('type filename.txt') do (
set in=%in%%%a
ffprobe "d:\Trainers\out\outt\!in!" 2>>info.txt
)
pause
The above script is placed in the folder containing ffprobe.exe & it successfully creates two txt files in the same directory
Note that d:\Trainers\out\outt\
is the directory to scan for media files & not the directory from where this bat file is executed
The basic syntax for ffprobe is
ffprobe "videofile"
Upvotes: 0
Views: 1734
Reputation: 11
The user input command looks like the wrong context. Drop the quotes and it should work properly. The quotes are not needed to separate your prompt from your user input.
Upvotes: 1
Reputation: 13196
Use a different variable name than path.
PATH
already does something really important. So important, in fact, that your changing it is precisely why the script is breaking.
More specifically, when you try to execute a program using just a filename (no path at all), if the program cannot be found in the working directory, the contents of the PATH
environment variable are searched. I haven't seen the error message you're getting, but it's probably failing to execute findstr, which is an executable typically found in a folder specified in PATH
.
Upvotes: 5