Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Simple, maybe confusing Perl task

Simple, maybe confusing Perl task

Simple, maybe confusing Perl task

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

RE: Simple, maybe confusing Perl task

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

RE: Simple, maybe confusing Perl task

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?

RE: Simple, maybe confusing Perl task

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.

$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

RE: Simple, maybe confusing Perl task

Yeah perfect!!!!  This works just the way I wanted it to...  Thanks a lot goBoating...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close