Deleting the contents of a folder

 
Post new topic   Reply to topic    Aprelium Forum Index -> Perl
View previous topic :: View next topic  
Author Message
hitam269
-


Joined: 10 Oct 2005
Posts: 4
Location: Franklin, TN

PostPosted: Sat Feb 25, 2006 11:19 pm    Post subject: Deleting the contents of a folder Reply with quote

This is part of a script which is supposed to delete all of the files in a user-specified folder which is located in htdocs\users. The script itself is also located in htdocs\users.

Code:
opendir(IMD, $infold);
@thefiles= readdir(IMD);
closedir(IMD);

print "Content-type: text/html\n\n";
print "<H1>Files Deleted</H1>";
print "Files deleted from folder $infold:<P>";

foreach $fileinfolder (@thefiles){
unless (($fileinfolder eq ".") || ($fileinfolder eq "..") || ($fileinfolder eq "index.html") || ($fileinfolder eq "Thumbs.db")){

unlink("\\$infold\\$fileinfolder");
print "$fileinfolder<BR>";
}}


The script mostly works perfectly; it opens the folder specified and prints the contents of the specified folder onto the screen. However, it always fails to delete the files. I've tried changing the line

unlink("\\$infold\\$fileinfolder");

to

unlink("\\users\\$infold\\$fileinfolder");

but that doesn't work. What should I do to make the script work as I intend?
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Feb 26, 2006 2:57 pm    Post subject: Re: Deleting the contents of a folder Reply with quote

hitam269,

Prepending the file paths in unlink with \\ makes Windows think the file is located in the root of the current drive (C: for example). So remove the leading \\ in order to have it access the file using its relative path.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
hitam269
-


Joined: 10 Oct 2005
Posts: 4
Location: Franklin, TN

PostPosted: Sun Feb 26, 2006 9:00 pm    Post subject: Reply with quote

Wow, thank you! That worked.
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Perl All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group