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

Not able to unlink the file

Status
Not open for further replies.

sappleg

Programmer
Apr 15, 2008
31
CA
Hi there,

I am trying to unlink a file, but even after supplying the command in my perl script, the file is still there in the directory. Following is my code:

$test_todb1 = $utils_dir."todb1.txt";

chdir ($utils_dir);
if (-e $test_todb1)
{
open(todb1file,$test_todb1);
$line = <todb1file>;
close (todb1file, $test_todb1);
if (substr($line,0,5) eq "TODB1")
{
&get_seq();
&insert_batch();
}
else
{
chdir ($utils_dir);
print ($utils_dir);
unlink ($test_todb1);
}
}

It's the last command 'unlink' where the problem is. I know that the text file doesn't contain the required text and the script is suppose to delete the file in this case. However, when I go to the directory the file is still there.

What am I doing wrong?
Your suggestions and help are most appreciated.

Thanks in advance.
 
unlink $test_todb1 or die "can't unlink $test_todb1 :$!\n";
see what that tells you.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks travs69. The error is 'Permission Denied'. However, I am able to delete the file manually.
 
Hi,
The issue stands resolved now. It was with the close filehandle. I closed the file and it's deleted with 'Unlink'.

Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top