Need some help
Moderator: DosItHelp
-
- Posts: 4
- Joined: 15 Apr 2011 12:01
Need some help
Hey guys I need some help with a batch file I am creating. I can't figure out how to list these media files on my computer
.mp3, mpa, .asf, .avi, .flv, .mov,
.mp4, .mpg, .swf, .vob, .wmv
I know I need to use dir but I can't figure it out. Any help would be appreciated!
Thanks!
.mp3, mpa, .asf, .avi, .flv, .mov,
.mp4, .mpg, .swf, .vob, .wmv
I know I need to use dir but I can't figure it out. Any help would be appreciated!
Thanks!
Re: Need some help
create text file with extensions, one per line
like this
ext.txt
This will list only filenames with extensions and store them in list.txt.
Or you can generate it from bat file:
like this
ext.txt
Code: Select all
mp3
mpa
asf
avi
flv
mov
mp4
mpg
swf
vob
wmv
Code: Select all
setlocal enabledelayedexpansion
for /f "tokens=* Delims=" %%a in (
ext.txt
) do (
set ext=%%a
dir *.!ext! /b /o:gn >>list.txt
)
This will list only filenames with extensions and store them in list.txt.
Or you can generate it from bat file:
Code: Select all
setlocal enabledelayedexpansion
echo off
echo mpa>>ext.txt
echo asf>>ext.txt
echo avi>>ext.txt
echo flv>>ext.txt
echo mov>>ext.txt
echo mp4>>ext.txt
echo mpg>>ext.txt
echo swf>>ext.txt
echo vob>>ext.txt
echo wmv>>ext.txt
for /f "tokens=* Delims=" %%a in (
ext.txt
) do (
set ext=%%a
dir *.!ext! /b /o:gn>>list.txt
)
del /q /f ext.txt
pause
Re: Need some help
'
Untested !
Code: Select all
@echo off &SetLocal EnableDelayedExpansion
set "$Field=mpa asf avi flv mov mp4 mpg swf vob wmv"
for %%! in (
!$Field!
) do for /f "usebackq tokens=*" %%! in (
`dir "*.%%~!" /b /o:gn`
) do echo.%%!
pause
EndLocal &exit /b
Re: Need some help
modified it a little to remove "file not found" from llist if no file with extenstion exist
Btw, what is %%! ? why it act so different and makes sing word as variable instead of whole line?
I never seen documentation of this, if only i knew i could use it i would not read extenstions from separate list.
Can you explain a little %%! and %%? or %%$ which you use quite offten?
Code: Select all
@echo off
SetLocal EnableDelayedExpansion
set "$Field=mpa asf avi flv mov mp4 mpg swf vob wmv"
for %%! in (
!$Field!
) do (
for /f "tokens=*" %%! in (
'if exist ^"*.%%~!^" dir ^"*.%%~!^" /b /o:gn'
) do (
echo.%%!
echo.%%!>>list.txt
)
)
pause
exit /b
Btw, what is %%! ? why it act so different and makes sing word as variable instead of whole line?
I never seen documentation of this, if only i knew i could use it i would not read extenstions from separate list.
Can you explain a little %%! and %%? or %%$ which you use quite offten?
Re: Need some help
'
enter this in your console:
I am not good in explaining things, you can find more help on for digging DOSTips.
enter this in your console:
Code: Select all
for /?
I am not good in explaining things, you can find more help on for digging DOSTips.
Re: Need some help
so you just use ! instead of alphanumeric values?
Re: Need some help
Using %%! %%? etc just confuses the newbies.
Re: Need some help
That has nothing to do with %%! ?, but rather with the default delimeters, {TAB}, {space}, {COMMA}Voodooman wrote:Btw, what is %%! ? why it act so different and makes sing word as variable instead of whole line?
I try,Voodooman wrote:Can you explain a little %%! and %%? or %%$ which you use quite offten?
Generally it is considered good programming style not to use variables when you don't have to.
These 'short lifespan' values can be represented with tokens like %a, %b, %? or even %!.
In the example above I used %! which I now consider bad style cause the exclamation mark is special and normally needs to be escaped in delayed expansion. This is problematic when writing macros.
So that leaves me with %a, %b or %?.
I suck at maths, but I do know my alphabet so I promote using tokens %a to %Z only when your for loop collects multiple 'tokens=1,2*'. In all other case, I use non-alphabetical tokens like %? to stand out.
I modify it again, you know it's faster to open a file for writing only onceVoodooman wrote:modified it a little to remove "file not found" from llist if no file with extenstion exist
Code: Select all
setlocal enableDelayedExpansion
set "$field=mpa,asf,avi,flv,mov,mp4,mpg,swf,vob,wmv"
> "list.txt" (
for %%? in (
!$field!
) do for /f "delims=" %%? in (
'2^>nul dir /b /o:gn "*.%%~?"'
) do (echo.%%?)
)
type "list.txt"
pause
exit /b
See ya,
Re: Need some help
Voodooman wrote:so you just use ! instead of alphanumeric values?
What made you come back to this thread 10 months later?
Last edited by Squashman on 21 Jul 2012 08:37, edited 1 time in total.
Re: Need some help
I realize the nice thing about looping through each extension one at a time is that you have each type then grouped together. But you could just do this down and dirty.
Code: Select all
dir /a-d /b /s *.mpa *.asf *.avi *.flv *.mov *.mp4 *.mpg *.swf *.vob *.wmv >VideoFiles.txt