to save video files names and length in a text file

HI
BY USING DIR command in msdos cmd promt i am getting to store my video files names in a folder but i require to get each video file length also..
please provide the command syntax or is there any tool available which helps to do that

thanks
darien_softwareAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
What length do you mean, just the bytes in the file, or the "time" length of the video, like 1:40.

~bp
Paul TomasiCommented:
bill
I think he wants the file length...

darien_software
Suppose your video file is named filename.mp4, you can do it like this (as a command):

    for %a in ("filename.mp4") do @echo %~za

or you can do it like this as a batch file:
@echo off
for %%a in ("filename.mp4") do echo %%~za

Open in new window


For a group of .mp4 files you can do this (display size and filename):

    for %a in (*.mp4) do @echo %~za %~na

A a batch fike, it would look like this:
@echo off
for %%a in (*.mp4) do @echo %%~za %~na

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
@Paul,

Yeah, I'm old school I guess, and it often costs me points on EE.  I prefer to ask questions on things that aren't clear to me and wait for a response before I invest time writing scripts.  Often while I'm waiting for clarification someone else comes along and takes a shot with some assumptions and gets the points.

It's all good though, I accept the downside of my approach and live with the consequences...

~bp
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Darr247Commented:
MediaInfo can tell you the playing length, along with a bunch of other info, like the audio bitrate, the framerate, et al, and can export that info to a text file a folder at a time, but I haven't played with it much... I just customized the 'Custom' View so it reads

General           : %FileName%
Length            : %FileSize_String% for %Duration_String1%\r\n

and ran it on my Alanis folder and got this output.

General           : Alanis Morissette-Hand in Pocket [live on Ellen 05-25-2005]
Length            : 125 MiB for 3mn 59s 282ms
Video #0          : MPEG-2 Video at 4 000 Kbps
Aspect            : 480 x 352 (1.364) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 320 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - You Learn (Live vh1.com) {vh1-bmt-imv}
Length            : 78.3 MiB for 3mn 57s 322ms
Video #0          : MPEG-2 Video at 2 487 Kbps
Aspect            : 480 x 480 (1.333) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 224 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis_Morissette_-_Hand_In_My_Pocket
Length            : 36.6 MiB for 3mn 40s 253ms
Video #0          : MPEG-1 Video at 1 150 Kbps
Aspect            : 352 x 240 (1.304) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 224 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - Head Over Feet
Length            : 45.3 MiB for 4mn 33s 73ms
Video #0          : MPEG-1 Video at 1 150 Kbps
Aspect            : 352 x 240 (1.304) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 224 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - Ironic
Length            : 42.9 MiB for 3mn 58s 681ms
Video #0          : MPEG-1 Video at 1 098 Kbps
Aspect            : 320 x 240 (1.333) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 384 Kbps
Infos             : 2 channels, 44.1 KHz

General           : Alanis Morissette - 2002 - 05 - Hand In My Pocket {SiG}
Length            : 146 MiB for 4mn 38s 678ms
Video #0          : MPEG-2 Video at 4 000 Kbps
Aspect            : 720 x 480 (1.333) at %fps% fps

Audio #0          : MPEG-1 Audio layer 2 at 320 Kbps
Infos             : 2 channels, 44.1 KHz

I think I need to play with the Custom View some more to get just what I want to be displayed.
Formatting is a little rough, too... the colons were all aligned; not sure what I did to muck that up.

Anyway... is that more like what you were asking for?
That shows the playing time down to the millisecond.
darien_softwareAuthor Commented:
hi
thanks everyone for the concern and response
i wanted the time length of the video file
and is it possible using a dos command??
but i think for now mediainfo software should help
Bill PrewIT / Software Engineering ConsultantCommented:
Here's a simple VBS script that will display the file name and then the duration of the video after it.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

Set objFileItem = objFolder.ParseName(objFile.Name)

WScript.Echo objFile.Path & "," & objFolder.GetDetailsOf(objFileItem, 27)

Open in new window

Save that as a VBS, let's say EE27659199.VBS.  Then you can use a small BAT file if you want to process all files in a folder like this:
@echo off
for %%A in (*.wmv *.avi) do cscript //nologo EE27659199.VBS "%%~A"

Open in new window

~bp
Darr247Commented:
Is there a redirect missing from the batch?

It looks like that will display, but I don't see how it writes the info to a file. (?)
Bill PrewIT / Software Engineering ConsultantCommented:
Yes, if you want to send the output to a text file you could redirect the output as in:
@echo off
for %%A in (*.wmv *.avi) do cscript //nologo EE27659199.VBS "%%~A" >>listing.txt

Open in new window

~bp
darien_softwareAuthor Commented:
HI THANKS FOR THE CODE
but the output am getting is this..

C:\Documents and Settings\Administrator\Desktop\demo\Algeb-33  Factorization-Using-Spl.products.avi,629 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Algebra-    Problems-Based-Laws-of-Set-operations-[Part-2]  A-{BnC}={A-B}U{A-C}.avi,609 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Men-26   Area-of-An-Equilateral-Triangle-with-Example.avi,623 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Ns-31   Problems-Based-on-Addiiton-of-Integers-[part-1].avi,663 pixels
C:\Documents and Settings\Administrator\Desktop\demo\Ns-63    Simplification-of-Fractions-With-Minus-And-Plus-Operations-[word problem] {part-2}.avi,628 pixels


i am not getting any time duration of each video file
Bill PrewIT / Software Engineering ConsultantCommented:
What version of Windows are you running?

~bp
darien_softwareAuthor Commented:
windows xp
darien_softwareAuthor Commented:
and if possible it iwll be very useful if i also get the size of the file in mb

so finally  i require
1.full name of the file
2.Duration(length in minutes) of the video file
3.Size of the file in mb
thanks
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, just for testing purposes, can you run the following VBS passing it just one of the video files?  So save as a VBS, let's save TEST.VBS, and then run from a command line like this:

cscript test.vbs "videofile.avi" >test.txt

Then paste test.txt back up here please.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Dim strAttrName(300)

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

for N = 0 To 300
   strAttrName(N) = Replace(objFolder.GetDetailsOf(Nothing, N), " ", "_")
Next

Set objFileItem = objFolder.ParseName(objFile.Name)

For i = 0 To 300
   if objFolder.GetDetailsOf(objFileItem, i) <> "" Then
      If Instr("objFolder.GetDetailsOf(objFileItem, i)", Chr(63)) then Wscript.Echo "FOUND"
      WScript.Echo "[" & i & "] " & strAttrName(i) & "=" & Replace(objFolder.GetDetailsOf(objFileItem, i), Chr(63), "")
   End If
Next

Open in new window

~bp
darien_softwareAuthor Commented:
ok
i have done it
here is the out put


Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

[0] Name=Algeb-33  Factorization-Using-Spl.products
[1] Size=61,480 KB
[2] Type=Windows Movie
[3] Date_Modified=6/24/2011 4:23 PM
[4] Date_Created=3/29/2012 12:35 PM
[5] Date_Accessed=4/3/2012 11:43 PM
[6] Attributes=A
[7] Status=Online
[8] Owner=VID1\Administrator
[21] Duration=0:35:41
[22] Bit_Rate=192kbps
[26] Dimensions=629 x 447
[27] =629 pixels
[28] =447 pixels
[32] Audio_sample_size=8 bit


bill
is it possible can u give me
only name of the file
duration
and size
and not in this format but in column wise and saved in excel format instead of txt
well i have hundreds of videos files and if each one is listed like this in text again i need to copy paste onto excel both duration and size which defeats the purpose of my interaction here
thanks in advance
darien_softwareAuthor Commented:
well if i run the cscript and save in xls format i am getting the same conents row wise
 i just need like in tabular wise

with first column having all the video names with no other options like the prev output has [0]name..but only the file name
second having corresponding duration in mins
third having the size of corresponding video in mb (instead of KB)
of all the videos in the same folder...
well my project requires these details and its urgent and i dont know vb code to do anything myself
so thanks for the help
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, try this.  The output of the BAT file will be a CSV which should open right up in Excel.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

Set objFileItem = objFolder.ParseName(objFile.Name)

WScript.Echo Quote(objFile.Path) & "," & objFolder.GetDetailsOf(objFileItem, 21) & "," & objFile.Size

Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

@echo off
echo Filename,Length,Size>listing.csv
for %%A in (*.wmv *.avi) do cscript //nologo EE27659199.VBS "%%~A" >>listing.csv

Open in new window

~bp
darien_softwareAuthor Commented:
hi
getting output
almost perfect with little issues
hope u can remove
getting the full file name instead of only the file name
if required only can u give hours i.e. HH option i mean none of my videos are more than 60 mins..
and size please give in mb instead of kb or bytes

listing1.csv
Bill PrewIT / Software Engineering ConsultantCommented:
Okay, give this a try.
If (WScript.Arguments.Count > 0) Then
  strFile = WScript.Arguments(0)
Else
  WScript.Echo "ERROR : No input filename specified."
  WScript.Quit -1
End If

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strFile) then
  WScript.Echo "ERROR : Input filename specified does not exist."
  WScript.Quit -1
End If

Set objFile = objFSO.GetFile(strFile)
strFolder = objFile.ParentFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strFolder)

Set objFileItem = objFolder.ParseName(objFile.Name)

WScript.Echo Quote(objFile.Name) & "," & Mid(objFolder.GetDetailsOf(objFileItem, 21), 3) & "," & Round(objFile.Size/1024/1024, 2)

Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
darien_softwareAuthor Commented:
thank you
this is 99.99% perfect except the time in microseconds which i will correct a very minor one...
thanks a lot
u have saved a lot of time for me..

listing.csv
Paul TomasiCommented:
99.99% eh?... Dreadful, isn't it?

With standards slipping that far down the scale, I'd seriously start thinking about repackaging some of those T-shirts - just in case!

:)
Paul TomasiCommented:
Was just kidding...

Well done bill. Code looks nice.

Was quite surprised to bag some points. Thank you.
Bill PrewIT / Software Engineering ConsultantCommented:
Glad that was helpful, thanks for the feedback.

~bp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.