Search code examples
powershellforeachexecutableget-childitem

Powershell send directory contents to a program


My goal is to translate .wav files in a directory using an executable which converts them to the proper audio format. Once these files are created, I then need to move everything out of the directory to another directory destination. What should happen is once the file executes the program (CommandLineConverter.exe) creates a new file in the correct audio format.

I tried Get-ChildItem pointing to the executable. Early on I ran into problems with the script accepting (x86). However, that seems resolved now and I don't any errors on debugging. The Move-Item is commented out for now because I'm trying to get the files to convert. Currently the script is not converting the files. There is no output that I can see.

I considered as an alternative just opening every item in the directory ($path) as I set the default for wave files to open in the CommandLineConverter.exe; however, that script didn't go well either.

Anyway here is the script that I have so far for sending directory contents to the executable which does not appear to be working as intended. Any help to point me in the right direction would be appreciated.

$path= "C:\Execuscribe\ExecuDropBox\Dropbox (ExecuScribe)\Conduent\Verizon"
$destination= "C:\Execuscribe\ExecuDropBox\Dropbox (ExecuScribe)\Converted"
Get-ChildItem $path | ForEach-Object 'C:\Program Files (x86)\Verint\Playback\CommandLineConvertor.exe'
#   {
        
 #       Move-Item -Path $file.fullname -Destination $Destination
#    }

Solution

  • Kirk,

    I think you want something along this line:

    $path= "C:\Execuscribe\ExecuDropBox\Dropbox (ExecuScribe)\Conduent\Verizon"
    $destination= "C:\Execuscribe\ExecuDropBox\Dropbox (ExecuScribe)\Converted"
    Get-ChildItem $path  -Filter "*.wav" | 
    ForEach-Object {
       &  'C:\Program Files (x86)\Verint\Playback\CommandLineConvertor.exe' $($_.FullName)
    
      $MIArgs = @{Path = $($_.fullname) 
                  Destination = "$Destination"}
       Move-Item @MIArgs
    }
    

    Add the -Filter parameter to Get-ChildItem to only retrieve .wav files. Call the program specifying each file as it comes down the pipe. I don't know how the converter's arguments are specified but the code included just contains the fully qualified filename you can add any identifiers that are required. Copy the converted file to the new location you'll have to replace NewExt with the output extension of the converted file.

    This is untested code!