Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to list and index files (video files such as .mp4, .avi, ... in my case) in a directory

I used :

setlocal disableDelayedExpansion
for /f "delims=" %%A in ('forfiles /s /m * /c "cmd /c echo @relpath"') do (
  set "file=%%~A"
  setlocal enableDelayedExpansion
  echo !file:~2!

But, this will only list files, and also include folder (i'd like the video files only). Exemple :


I also don't want theses : "script.bat" and "exportfolder"

I know that if i put *.avi in the forfiles line, I won't have this probleme anymore, but i'll have to duplicate theses lines of script for eatch video format ... not very cool, right ?! It would be better if I exclude the directories and files I know I don't want to list, no ?

I think I have to put "/a-d" somewhere to hide directories, but where ?

But to hide the files I don't want to be listed and indexing the rest (give eatch of them a usable variables names and number), I have no clue ... perhapse somewhere near the "!file:~2!" line ?!

Anyway, let me show you what I'd like to have :

1. "video01.mp4"
2. "video02.webm"
3. "video03.avi"
4. "exportfolder\video04.avi"
5. "exportfolder\video05.mpg"

this would give the user of the script to pick a file of he's choice with something like :

set /p choice=What is the file you want to use ?
if %choice%==1 set file=indexlist1
if %choice%==2 set file=indexlist2
if %choice%==3 set file=indexlist3 
if %choice%==4 set file=indexlist4 

and the script will proceed with the selected file ... if I manage to catch the value for the printed index file I want.

I hope you see what I'd like to do ?!

That's a lot of questions, know, but any help would be great !

Thanks !


share|improve this question
This will quickly become unmanageable if there are lots of videos and the command prompt window starts scrolling like crazy. Can you state your actual problem? A batch file may not even be required to do what you really want, and maybe we can suggest better solutions. Also be sure to mention which version of Windows you are using. – Karan May 22 '13 at 22:51

I'm running the script on windows 8 or 7 only ;)

And as for a huge number of videos or files that will make the windows cmd scrolling like crazy: this script is meant to bo used only inside my company, and only for a few users (mostly editors or cg editors). for exemple a warning in the script should suffice to alert the user to not run the script in a folder that contains a huge amount of files or videos.

But I agree, this "forefiles" cmd is very slow ... even in small folder (few files).

My actual problem is that for a single project, there can be multiple video files (due to client needs for exemple), and i wanted to give the ability to the user to choose in this package of videos, the one (or some ... but thats another question ... again) he needs to proceed, and then send it, for validation purpose for exemple, or even batch resizing, ... anything is possible ;)

I ask mysefl about softwares already devellopped, that can completely do the job ... but no exactly the way I want, and with a lot more clicks, more time and less direct control or less specific needs , to have the result the script will be able to deliver.

Yes I got myself into the principle of "time is money" thing ... sadly i'd say. ^^

So, knowing all that, is my idea something that can be done this way ?

For now, i'm testing the script, and I make it work by having a specific naming format for the input file, but i'd like to get rid of that ! :)

thanks, I hope I answered you right and you'll be able to put me on tracks !

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.