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!

Simple, maybe confusing Perl task

Status
Not open for further replies.

damann

Technical User
Jul 19, 2000
114
US
I have a quick, kinda confusing question...

I have a script that moves my mp3 files from my napster's "music" folder, rename them and then move it to another folder on my system. I run into a problem though. While some of my files are being downloaded from napster and I run my script, the script will try to move those files. I dont want that to happen. I want my script to skip the files that are currently being downloaded and only move the ones are finished downloaded. I don't know how to do this however...

Did I lose you? Let me know
 
I don't know if will work, but, you might be able to use a file test operator to see if the file is writable. I would hope that if the file is still downloading, the process that is doing the download would have the file locked, not-writable. If that is the case,....

if (-w) { `mv $file $newfile`; }

'hope this helps....


keep the rudder amid ship and beware the odd typo
 
yeah the thing is, when it's still being downloaded and my script runs on it, I get a message saying "The process cannot access the file because it is being used by another process", but I still get a not finished copy if the file moved. This is what I want to avoid. So I dont think that piece of code you provided would work.

My idea was to pipe the results of my code to perl and if that message is identified, using perl matching, then it would skip that file. But I don't know how to get that idea into code...

What do you think?
 
I don't see why a file test operator won't do what you want..... I wrote this little chunk which tries to rename a file. If that file is open in Word, I get the same message you refer to. If I do not have the file open in Word, the file gets renamed.

#!perl
$file = 'D:\temp\temp.doc';
if (-w $file)
{
`rename $file Imoved.doc`;
}

You must be producing a list of files that are subsequently moved..... the file test should tell you wether or not each file is writable. If it is, move it. If not, leave it alone.


opendir(DIR,"YourSourceDir") or die "Failed to open source directory, $!\n";
@files = readdir(DIR);
closedir DIR;

foreach $file (@files)
{
if (-w $file)
{
# move the file
}
else { print "File is not available yet.\n"; }
}


Is this not what you are trying to do???? <scratching the head slowly??>

'hope this helps...


keep the rudder amid ship and beware the odd typo
 
Yeah perfect!!!! This works just the way I wanted it to... Thanks a lot goBoating...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top