![]() |
| Perl File::Copy problems |
|
paul28
|
Hi all, i'm trying to copy a list of files from one location to another. But after perl does the work of reading the paths from the list, the copy command doesn't work. weird thing is, when i have perl print the paths to the screen, and i manually copy and paste one of them directly into the copy command, it works. Whats going on?
|
||||||||||||||
|
|
|||||||||||||||
|
cheryl
|
Are you trying to run the perl script from the web or just from the command prompt? If you are running the perl script from the internet, it is possible that the directory you are trying to write to does not have permissions to do so. If you are running it from the command prompt, what is the error that you are getting?
|
||||||||||||
|
|
|||||||||||||
|
paul28
|
Thats the thing, there is no error, it continues comparing file names, and goes through that copy command as if it did it, only it didnt actually copy anyhitng. i think it has something to do with the $patha string being weird somehow. dont know. And yes, this is only local on the command prompt.
|
||||||||||||
|
|
|||||||||||||
|
cheryl
|
I believe the situation is that you need to remove the whitespace from the end of the filename of $patha - at least, that is what I needed to do to get the code to work when I tested it out. I trimmed the whitespace by using the split function:
my @tmpPath = split(/\s+/, $patha); then reset $patha back to $tmpPath[0] I would recommend doing the same for $pathb. I hope this helps! |
||||||||||||
|
|
|||||||||||||
|
paul28
|
Thank you, i'll try it out.
|
||||||||||||
|
|
|||||||||||||
|
paul28
|
no, this doesn't quite work because i have folders with multiple words, and taking [0] of that new array only takes the path until the first space. i'm not sure how to do it, but i need everything but the last [$]. I'll try again.
i get this now: /Users/paul/Music/iTunes/iTunes i need this (and only this): /Users/paul/Music/iTunes/iTunes Music/50 Cent/Unknown Album/Get Rich or Die Tryin.mp3 i think it must be something like this white space thing, but when i print "-$patha-" the dashes are directly on either side. so doesn't that mean that there isn't any trailing whitespace? |
||||||||||||
|
|
|||||||||||||
|
cheryl
|
It does sound like it...can you post a sample of the file you are reading in so I can make sure I'm using the same format? Also, when you run the copy function, maybe try doing:
copy ($patha, $pathb) or die "copy failed: $!"; That should at least show you why the copy failed - that's how I came across the spaces thing. |
||||||||||||
|
|
|||||||||||||
|
paul28
|
Ok, my project has taken a bit of a turn. Let me explain. From the begginning, i had a pl script that compared two lists of songs from iTunes. In this script, when it found one that the other list didnt have, it was suppoesed to send copy it to another central location for importing to the other iTunes. Problem was, that copy command never works, except when i copied it manually. So i tried to have the computer copy it so to speak. it was a bit of a work around. I wrote this second script, the one i showed here, which was suppoesed to copy songs from a list that the first script created. Problem was, this didn't work either. Thats when i posted here. In the mean time, i can up with another workaround that worked. I had the first script compare and create a path list - in a very specific format. Then i manually copied the entire list at once, and pasted it into a list variable in an applescript script, which conveniently did the copying. So, as i see it now, im scraching the script i posted here, it was a workaround that didnt work. I'll post the origional pl script, although now set up to create the file for applescript to use. It would still be great to get perl to do the copying itself, but not really necessary anymore. From this script you can see how the old path list was created. I think it was:
"$path\t \n" the purpose of this was to split each line at the tab, therby leaving the return in the unused half, and not having to deal with it. Anyway, my question is now, why wouldn't it copy($patha, $pathb) in this script to start with? Please note that the format of the paths is for applescript now, but you can figure out what it means. : instead of /, and you have to state the drive instead of just / Thanks for your help!
|
||||||||||||||
|
|
|||||||||||||||
| Try this trick, it worked for me! |
|
uma
|
Hi everybody,
I am a newby to Perl programming! I was trying to copy files from one directory to another and had the same problems as you! My colleague pointed out that I can use: system("cp $fileName ./destinatiodir/$fileName"); This definetly works! Same rule applies to mkdri, rm, mv etc.......! Good Luck -U |
||||||||||||
|
|
|||||||||||||
|
paul28
|
Thanks, but that doesn't help me, because my path variable was sumehow corrupted so to speak from the beginning, I couldn't just type the path in, it had to get pulled out of a file and reformatted, the problem was there. But thanks. You said your colleague, out of curiosity, what do you do for a living? I'm a senior in high school, and I'm just curious what there is out there that includes some casual programming but thats not the main job.
|
||||||||||||
|
|
|||||||||||||
| Perl File::Copy problems |
|
||
|


