tomfmason Posted August 7, 2006 Share Posted August 7, 2006 I wrote a function that will create a directory and add a file to it. Now I am wondering how I can delete a directory and/or a file. I don't want anyone to write the function for me but rather point me in the right direction i.e.. a link to a relivant section in the manual or an example.Any suggestions would be great.Thanks,Tom Link to comment https://forums.phpfreaks.com/topic/16773-delete-a-file/ Share on other sites More sharing options...
Orio Posted August 7, 2006 Share Posted August 7, 2006 For a file- [url=http://www.php.net/manual/en/function.unlink.php]unlink()[/url]For a dir- [url=http://www.php.net/manual/en/function.rmdir.php]rmdir()[/url]Orio. Link to comment https://forums.phpfreaks.com/topic/16773-delete-a-file/#findComment-70550 Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Author Share Posted August 7, 2006 thanks orio. That is exactly what I was looking for.Thanks for the help,Tom Link to comment https://forums.phpfreaks.com/topic/16773-delete-a-file/#findComment-70552 Share on other sites More sharing options...
tomfmason Posted August 7, 2006 Author Share Posted August 7, 2006 I tried using [code=php:0]chdir ($file_system_path);exec ("del *.* /s /q");[/code]And it delted everything in the current directory that I had the file that was running the code. It is a damn good thing that I used a test directory in local host..lolThis is dangerous if you do not know what you are doing.Thanks,Tom Link to comment https://forums.phpfreaks.com/topic/16773-delete-a-file/#findComment-70557 Share on other sites More sharing options...
zq29 Posted August 7, 2006 Share Posted August 7, 2006 [quote author=tomfmason link=topic=103258.msg411085#msg411085 date=1154944568]I tried using [code=php:0]chdir ($file_system_path);exec ("del *.* /s /q");[/code]And it delted everything in the current directory that I had the file that was running the code. It is a damn good thing that I used a test directory in local host..lolThis is dangerous if you do not know what you are doing.Thanks,Tom[/quote]Indeed. '*.*' will delete all files with an extension as the * character is used as a wildcard, /s flags all sub-directories for deletion, and /q runs in quiet mode - just deleting without prompting. Link to comment https://forums.phpfreaks.com/topic/16773-delete-a-file/#findComment-70569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.