0

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"
1
  • 1
    Windows environment variables are not case sensitive. Don't use %path%. That aside, you're sure that the variable is getting the value you expect? Commented Oct 30, 2012 at 13:37

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@nightcrawler: for a list of other variables you shouldn't use, pull up a command prompt and issue the command set.
wow! there is a lot of info hardware info there...quiet useful. Such invisible commands I don't know about :( would you like t suggest some book for me. Ido know a lot about Javascript & webcoding but not about this
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.