perlquestion
amateur_programmer54
<P>Dear Monks,</P>
<P>I am trying to write a small Perl script to run an executable file. I want the .exe file to work on the entire contents of a data directory. I’d like to be able to run the final perl program on machines that run Windows XP or Windows 7.</P>
<P>The “System” command doesn’t seem to work for what I am doing and I must include both input and target file names and paths after the executable file name and I am attempting to mix paths with a variable from an array.</P>
<P>The program converts .MID files to .CSV files when run stand alone. Once I have edited the .CSV file I will convert it back to .MID format with another similar file.</P>
<P>The syntax I would use after a command prompt to convert one file at a time,
is as follows:</P>
<P>C:\directory\midicsv.exe c:\path\input_file.mid c:\path\target_file.csv</P>
<P>I would like to keep the names of “input_file” and “target_file” the same other than the extension. “Input_file” may be a name that includes the character _</P>
<P>I am trying to convert files in batches. In order to do that I am capturing all the file names in a given data directory to an array, and was hoping to use the file names saved in the array as part of the input_file name string.</P>
<P>Below is what I have written so far. I am getting the following error:
“C:midicsvmidicsv.exe’ is not recognized as an internal or external command.”
What am I doing wrong?</p>
<P>Can I mix an array variable with a Path? If so can you give me the proper syntax? If not, how can I insert the filenames after the name of the .exe I am calling?</P>
<P>Can I rename all the files to similar names ending in .CSV, and establish an output path to a different directory?</P>
<code>
my $directory = 'c:\midicsv\newmidi';
opendir(DIR,$directory);
my @files = readdir(DIR);
closedir(DIR);
#the following line is not truly necessary but I left it in so I could see that the file names were being captured.
foreach(@files){ print $_,"\n";}
#this is the line giving me trouble,
foreach(@files) {system("c:\midicsv\midicsv.exe", "c:\midicsv\newmidi\$_", "c:\midicsv\newcsv\$_");}
</code>