View previous topic :: View next topic |
Author |
Message |
hitam269 -
Joined: 10 Oct 2005 Posts: 4 Location: Franklin, TN
|
Posted: Sat Feb 25, 2006 11:19 pm Post subject: Deleting the contents of a folder |
|
|
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 |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sun Feb 26, 2006 2:57 pm Post subject: Re: Deleting the contents of a folder |
|
|
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 |
|
|
hitam269 -
Joined: 10 Oct 2005 Posts: 4 Location: Franklin, TN
|
Posted: Sun Feb 26, 2006 9:00 pm Post subject: |
|
|
Wow, thank you! That worked. |
|
Back to top |
|
|
|