hi, y'all,

last night i tried getting a perl script i wrote to change long filenames on a win32 
platform, or to copy the files to another directory with changed names. the filenames 
are formatted like this: nn - xxxxxxxx - xxxx.fff, where n's are numbers, x's are 
strings, \s-\s is a delimiter; and f's are file extension. more specifically, the 
filenames are of mp3's from my jukebox that i transfer to my palm sd/mmc. nn's are 
track numbers,  the first string is artist, the second is song name; and the file 
extension is mp3. for example, 05 - Flack, Roberta - Feel Like Makin' Love.mp3. the 
script should change the filenames, eliminating track number, starting the filename 
with song name, followed by delimiter, then artist; ending with file extension. for 
example, Feel Like Makin' Love - Flack, Roberta.mp3

the script i wrote is below, the system() command the last variation on that line of 
code before i gave up:

opendir(NT, "c:/Media/Music/palm");

    while($name = readdir(NT)) {
 @nameArray = split(/\./, $name);
 @fields = split(/\s-\s/, $nameArray[0]);
 $newName = $fields[2] . " -  " . $fields[1] . ".mp3";
 $oldName = $name;
 system(copy "c:/Media/Music/palm/$oldName", "c:/Media/Music/palm/$newName");
    }

closedir(NT);

i also tried the rename() command, as well as the native ren command. i couldn't get 
what i want in perl, so i wrote this vbs (which works):

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Media\Music\faves")
Set colFiles = objFolder.Files
For Each objFile in colFiles
 fileName = objFSO.GetFileName(objFile)
 newFileName = Right(fileName, Len(fileName)-5)
 newFileName = Left(newFileName, Len(newFileName)-4)
 arrayNewFileName = split(newFileName, " - ")
 newFileName = arrayNewFileName(1) & " - " & arrayNewFileName(0) & ".mp3"
 objFSO.CopyFile "C:\Media\Music\faves\" & fileName , "C:\Media\Music\palm\" & 
newFileName
 'WScript.Echo newFileName
Next

MsgBox "Finished!"

i'm supposing the problem lies with my not getting the typography or syntax right for 
filenames that can have all kinds of typography in them. could somebody kindly set me 
straight on what would have made my perl script run so that i wouldn't have had to 
have done a vbscript?

thanks,
james

Reply via email to