kbass
Mon Mar 03 10:41:25 CST 2008
On Mar 3, 11:18 am, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "kbass" <kyle.bass...@gmail.com> wrote in message
>
> news:85ecddd8-17bb-4e74-8e3b-dec0f50276c7@u10g2000prn.googlegroups.com...
>
>
>
> > On Mar 3, 12:13 am, "Todd Vargo" <tlva...@sbcglobal.netz> wrote:
> >> Pegasus (MVP) wrote:
> >> > "Kyle" <K...@discussions.microsoft.com> wrote in message
> >> >news:404F42AF-DC5F-4457-A19E-EECB41E505E6@microsoft.com...
> >> > >I believe this is called DOS batch scripting. I found this example
> >> > >via
> >> > > Google. It contains much of the same commands, such as tokens, and
> >> > > delims,
> >> > > as what I need to translate. How can I translate this code into VBS ?
>
> >> > > SET SIZE1=0
> >> > > SET SIZE=0
> >> > > FOR %%i in ("DIR /B "D:\*.m2v") DO ECHO %%~zi >>D:\size.txt
> >> > > FOR %%i in ("DIR /B "D:\*.m2v") DO ECHO d:\%%i + >>D:\list.txt
> >> > > FOR /F "tokens=*" %%i in ('type "d:\list.txt"') DO SET LIST=%%i
>
> >> > > FOR /F "tokens=*" %%i in ('type "d:\size.txt"') DO SET /A
> >> > > SIZE1=%%i+%SIZE1%
>
> >> > "DOS" could never do this sort of thing but the Command
> >> > Prompt under Windows can. Here is an explanation of each
> >> > command. All of them have their equivalents in the VB Script
> >> > "File System Object".
>
> >> > FOR %%i in ("DIR /B "D:\*.m2v") DO ECHO %%~zi >>D:\size.txt
> >> > Write the size of each *.m2v file to D:\ to D:\size.txt.
>
> >> > FOR %%i in ("DIR /B "D:\*.m2v") DO ECHO d:\%%i + >>D:\list.txt
> >> > Write the name of each *.m2v file to D:\ to D:\list.txt.
>
> >> First of all, the two for commands contain unbalanced double quotes. As I
> >> recall, the NT line (what this code is for) balks at unbalanced quotes.
> >> Secondly, the /F switch was not used so even if dbl-quotes were balanced,
> >> all the FOR command would do is pass the quoted string "DIR /B D:\*.m2v"
> >> as
> >> plain text, not a list of *.m2v files as expected.
>
> >> FOR %%i in (D:\*.m2v) DO ECHO %%~zi >>D:\size.txt
> >> FOR %%i in (D:\*.m2v) DO ECHO %%~fi >>D:\list.txt
>
> >> > FOR /F "tokens=*" %%i in ('type "d:\list.txt"') DO SET LIST=%%i
> >> > Set the LIST environmental variable to the last line found in
> >> > "list.txt".
>
> >> > FOR /F "tokens=*" %%i in ('type "d:\size.txt"') DO SET /A
> >> SIZE1=%%i+%SIZE1%
> >> > Set the SIZE1 environmental variable to the sum of all file sizes.
>
> >> > The commands don't make a great deal of sense. In its current
> >> > form the batch file is incomplete and some of its tasks could be
> >> > solved in more elegant ways.
>
> >> I agree. Basically, one can not translate non-working code reliably,
> >> however, the following should help OP along. HTH
>
> >> path = "D:\"
> >> ext = "m2v"
> >> Set fso = CreateObject("Scripting.FileSystemObject")
> >> Set f = fso.GetFolder(path)
> >> Set fc = f.Files
> >> For Each f1 in fc
> >> If Ucase(fso.GetExtensionName(f1)) = Ucase(ext) Then
> >> list = list & f1.Name & vbcrlf
> >> size = size + f1.Size
> >> End If
> >> Next
> >> Wscript.Echo list, " ", size, "bytes"
>
> >> --
> >> Todd Vargo
> >> (Post questions to group only. Remove "z" to email personal messages)
>
> > Thanks all. I want to understand this logic, but I have a large task
> > at hand and little time to complete it. It would be easiest for me,
> > if I could find some sort of app/program to translate this code into
> > VBS.
>
> > What does .."OP"....stand for..in Pegasus' post ? Thanks for the link
> > to that group Pegasus.
>
> By the way, I note that you posted the same question in a Windows
> Batch group. There is nothing wrong with posting the same question
> in several groups, provided you do it correctly, i.e. by "cross-posting".
> If you "multi-post" (as you did) then your popularity rating will drop
> very quickly because muli-posting result in duplication of effort and
> therefore causes waste of time.
>
> See here for the details:
http://www.blakjak.demon.co.uk/mul_crss.htm
AH. I see what happened now. My apologies. I was not sure where I
should be posting. I will keep this question in the other forum you
gave me. Again, my apologies.