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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unlink on win32 1

Status
Not open for further replies.

Arion23

IS-IT--Management
Mar 29, 2001
132
AU
Hi all,

I've written the following perl code to check if a temporary file is older than 0.01 days (about 15 minutes it works out) and if it is, to unlink/delete it.

I intend for this code to loop through all the files in a given directory, resulting in only the most recently created files are left.

Sample #1
foreach $drop_file (<files/*.*>) {
if( (-C $drop_file) >= 0.01 ) {
system(&quot;del $dropfile&quot;); }
}
}

Sample #2
foreach $drop_file (<files/*.*>) {
if( (-C $drop_file) >= 0.01 ) {
unlink($drop_file); }
}
}

I've tried both the system(&quot;del...&quot;) and unlink methods, by neither seem to work...

Any thoughts?
 
Both methods work for me on Win NT (perl 5.6.0). I tried both samples and they both work with the following setup. Perl script in a directory containing a sub-directory named files. This subdirectory contains some files. Maybe its not a problem with deleting, but a problem with file permissions, being in the right directory, or the files being in use. Try the following code to see if you can &quot;unlink&quot; at all.

$File = &quot;dummyfile&quot;;
open(F, &quot;>>$File&quot;) or die &quot;Can't open $File: $! \n&quot;;
print F &quot;This is a test \n&quot;;
close(F);
system(&quot;type $File&quot;);
unlink($File);
system(&quot;type $File&quot;);

You should get the following output:
This is a test
System cannot find the file specified
 
Thanks for the info, it did turn out to be a permissions problem...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top