Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to automate manual file conversion 5

Status
Not open for further replies.

Gaffi1

Technical User
Apr 23, 2004
70
US
Hi, we are currently recording sound files in rhet32 format and need them in wav8. We have a utility that converts the files for us, but it requires we type a command into a cmd prompt for every single audio file and this is becoming a pain staking process.

The command that we pass through the cmd prompt is:
Conv32 /it:rhet32 /ot:wav8 s0123456.123 s0123456.wav

The idea I was hoping of coming up with is a script that pulls a list of all files in a directory and if it's not a .wav file execute that command on it and move the original file to archives; then move on to the next file until non remain.

I've looked around for ideas of varying degree and none have worked so far. The two problems I have are a) getting the list of files and b) getting the conv32 command to work using variables. Example below:
set strFile = s075134j.066
set strNewFile = jamestest.wav
conv32 /it:rhet32 /ot:wav8 strfile strnewfile

This problem however passes the literal text "strfile strnewfile" to the command instead of their values.

Any suggestions on how I can bypass these two problems?
 
You can use the FileSystemObject to get a Folder object.
The Folder object has a property named Files.
Files is a collection of File objects.

So you could make a For Each/Next loop to go through each File object in the Files collection. By examining the properties of the File object you will determine the file extension, and thus whether or not it needs to be converted.

 
Oh, and then you build a command string and execute it using WshShell.Run.


So search this site and google for the nitty gritty details on FileSystemObject and WshShell.Run
 
OK, here is what I have so far...
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile in colFiles
    If objFile.Extension = "066" Then
        strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
        strNewFile = "C:\test\" & objFile.FileName & ".wav"
	MsgBox strFile
	MsgBox strNewFile
    End If
Next

I'm not 100% sure how to pass this through the cmd prompt now though. After running this script, what should happen is the following command:
Code:
conv32 /it:rhet32 /ot:wav8 strFile strNewFile

which would replace the manual version of:

conv32 /it:rhet32 /ot:wav8 s0123456.066 s0123456.wav

Thanks for your help!
 
Just use the rename method.
[tt]
dim iret
If objFile.Extension = "066" Then
'strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
strNewFile = "C:\test\" & objFile.FileName & ".wav"
[blue]on error resume next
iret=objFile.rename(strNewFile)
on error goto 0[/blue]
'MsgBox strFile
'MsgBox strNewFile
End If
[/tt]
 
Further note:
In terms of speed, you should really use filesystemobject to do it. Wmi way of doing it is much slower, but I don't blame it---it is just not operating on the same scope as fso.
 
unfortunatly we can't just rename because the conv32 utility is used to actually convert the audio formatting. Rhet32 stands for rhetorex which is an audio recording of phone calls for quality assurance purposes. We use the conv32 utility to convert from rhet32 to wav8 so that modern software can listen to the calls and coach the agents. Simply renaming would be like taking a .exe and renaming it to .wav and expecting it to be able to play.

As to using filesystemobject, please forgive me. I tried looking it up last night but didn't come accross any definitive examples on how to use it, mainly because my vbscript experience almost comes completely from designing db's in access.

Would you say that this is a hopeless cause?
 
you are close, try this:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile in colFiles
    If objFile.Extension = "066" Then
        strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
        strNewFile = "C:\test\" & objFile.FileName & ".wav"
        [b]callapps "c:\yourpath\conv32 /it:rhet32 /ot:wav8 " & strFile & " " & strNewFile[/b]
    End If
Next

This sub calls executables:

Code:
sub callapps(app)
	Dim MyObj
	Set MyObj=CreateObject("WScript.Shell")
	MyObj.Run app
end sub

Hope this helps...
 
I see, sure it is not rename!

[1] You instantiate a wshshell object anywhere outside the loop.
[tt] set wshshell=createobject("wscript.shell")[/tt]

[2] Inside the if-end if, call its .run method.
[tt]
If objFile.Extension = "066" Then
strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
strNewFile = "C:\test\" & objFile.FileName & ".wav"
wshshell.run "conv32 /it:rhet32 /ot:wave8 " & """strFile""" & " " & """strNewFile""",0,true
'MsgBox strFile
'MsgBox strNewFile
End If
[/tt]
You might have to supply the full path to the conv32 if needed.

[3] Clear up wshshell after the loop. But since you show nothing on even cleaning up objWMIService etc, so I leave it up to you for future refinement. At present you have to make the .run line running properly.
 
Amendment

I mess up quotes!!! A retake with additional focus on the conv32.
[tt]
[blue]wshshell.currentdirectory="c:\program files\xyz" 'set your path to conv32.exe[/blue]
If objFile.Extension = "066" Then
strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
strNewFile = "C:\test\" & objFile.FileName & ".wav"
wshshell.run "conv32 /it:rhet32 /ot:wave8 " & """" & strFile & """" & " " & """" & strNewFile & """",0,true
'MsgBox strFile
'MsgBox strNewFile
End If
[/tt]
 
I think we are really really close on this....
Here is what I am currently using:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set wshshell=createobject("wscript.shell")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
        & "ResultClass = CIM_DataFile")

wshshell.currentdirectory="c:\test\"    'set your path to conv32.exe
If objFile.Extension = "066" Then
    strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
    strNewFile = "C:\test\" & objFile.FileName & ".wav"
    wshshell.run "conv32 /it:rhet32 /ot:wave8 " & """" & strFile & """" & " " & """" & strNewFile & """",0,true
    'MsgBox strFile
    'MsgBox strNewFile
End If

I am getting the following error information:
Code:
Windows Script Host
Script: C:\test\convert.vbs
Line: 10
Char: 1
Error: Object reguired: 'objFile'
Code: 800A01A8
Source: Microsoft VBScript runtime error
Any suggestions with this error?


Thanks to all of you for your help so far, i really do appreciate it. I'm learning so much!
 
You've lost your for next loop identifying what objFiles you are talking about.

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set wshshell=createobject("wscript.shell")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
        & "ResultClass = CIM_DataFile")

wshshell.currentdirectory="c:\test\"    'set your path to conv32.exe
For Each objFile in colFiles
  If objFile.Extension = "066" Then
      strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
      strNewFile = "C:\test\" & objFile.FileName & ".wav"
      wshshell.run "conv32 /it:rhet32 /ot:wave8 " & """" & strFile & """" & " " & """" & strNewFile & """",0,true
    'MsgBox strFile
    'MsgBox strNewFile
  End If
Next
 
That's actually what I thought at first and I got this message when I added the next originally so i had removed it, sorry :(:

Code:
Windows Script Host
Script: C:\test\convert.vbs
Line: 17
Char: 1
Error: Unexpected 'Next'
Code: 800A041F
Source: Microosft VBScript compilation error

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set wshshell=createobject("wscript.shell")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
        & "ResultClass = CIM_DataFile")

wshshell.currentdirectory="c:\test\"    'set your path to conv32.exe
	If objFile.Extension = "066" Then
    		strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
    		strNewFile = "C:\test\" & objFile.FileName & ".wav"
    		wshshell.run "conv32 /it:rhet32 /ot:wave8 " & """" & strFile & """" & " " & """" & strNewFile & """",0,true
    		'MsgBox strFile
    		'MsgBox strNewFile
	End If
Next
 
well shoot... I figured out what I was missing, a whole line of code, lol... not sure where it went it used to be there....

For Each objFile in colFiles

However, when i run the script now it hour glasses like its doing something and then nada happens....?
 
I think you've got some quote problems on your wscript.run line.

Try
Code:
CommandText = "conv32 /it:rhet32 /ot:wave8 " & """" & strFile & """" & " " & """" & strNewFile & """"
wscript.echo CommandText
wshshell.run CommandText,0,true

Then look at the screen echo and see if it looks EXACTLY like a command that would work typed as is at the command prompt.

 
I also think you should go with FileSystemObject - much cleaner & probably quite faster. Here's a sample using your folder that I think will just work for you:

Code:
set wshshell=createobject("wscript.shell")
Set FSo = CreateObject("Scripting.FileSystemObject")
Tmpdir= "C:\test"
wshshell.currentdirectory="c:\test\"    'set your path to conv32.exe
Set oFolder = fso.GetFolder(TmpDir)
For Each objFile In oFolder.files

'your loop goes in here
  If objFile.Extension = "066" Then
    strFile = "C:\test\" & objFile.FileName & "." & objFile.Extension
    strNewFile = "C:\test\" & objFile.FileName & ".wav"
    CommandText = "conv32 /it:rhet32 /ot:wave8 " & strFile & " " & strNewFile
    wscript.echo CommandText ' remove this line if it works to let it process without hitting keys
    wshshell.run CommandText,0,true
    'MsgBox strFile
    'MsgBox strNewFile
  End If
Next
 
Jerz, thanks for your help on this... you were right, it's not pushing out exactly what its supposed to.

instead of pushing out
Code:
conv32 /it:rhet32 /ot:wav8 s075134j.066 s075134j.wav

it's pusing out
Code:
conv32 /it:rhet32 /ot:wav8 "c:\test\s075134j.066" "c:\test\s075134j.wav"

So, I tweaked it a bit to:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set wshshell=createobject("wscript.shell")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
        & "ResultClass = CIM_DataFile")

wshshell.currentdirectory="c:\test\"    'set your path to conv32.exe
For Each objFile in colFiles
	If objFile.Extension = "066" Then
    		strFile = objFile.FileName & "." & objFile.Extension
    		strNewFile = objFile.FileName & ".wav"
    		wshshell.run "conv32 /it:rhet32 /ot:wav8 " & "" & strFile & "" & " " & "" & strNewFile & "",1,true
		CommandText = "conv32 /it:rhet32 /ot:wav8 " & "" & strFile & "" & " " & "" & strNewFile & ""
	End If
Next
[code/]

now this works nearly perfect.  It found a .066 file converted it just likes it supposed to, however, it stopped and didn't find the second .066 file I had sitting there.  Do I need to add some more code to the next function?
 
To be honest, I don't use WMI query you are using to get your file list. See my FSO code posted today at 14:01, just before your last post. (clean out the paths from the str variables like you did in your recent post) I use this same logic and parse through lists of files in a folder looking for particular ones.
 
Are you certain that the following line is working:[tt]
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\test'} Where " _
& "ResultClass = CIM_DataFile")[/tt]

... because if colFiles does not actually contain all files then that would certainly explain why the loop didnt process the other 066 file.

Why not use the FSO Folder?
 
ok, I just happened to be in in task manager to clear out some processes and found a bunch of conv32 processes in the list. I killed a few and bing bada boom it went to the next file. So I'm guessing I need some sort of cleanup process (which I think someone previously mentioned) before the next step. I'm just not sure exactly what, lol. I'm used to just executing commands to open up forms, run some reports, etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top