Posted: Thu Apr 19, 2007 9:36 am Post subject: Recursion for deleting
Having a bit of difficulty making a procedure that deletes all the dirs and files within a dir. Heres my code so far. Sorry about the lack of commenting and the messyness.
Turing:
var temp :string var streamNumber :int
function slash :string iflength(Dir.Current)=3then%if you are at the root of a drive result"" else result"/" endif end slash
Just call delete2 with the folder you want to delete as the parameter to test.
Sponsor Sponsor
ericfourfour
Posted: Thu Apr 19, 2007 4:25 pm Post subject: RE:Recursion for deleting
All of that code can be replaced with Dir.Delete (path).
Carey
Posted: Mon Apr 23, 2007 6:57 am Post subject: Re: Recursion for deleting
In what version of Turing? Ive got 4.0.5. is it different in 4.1?
Turing 4.0.5 Help wrote:
Dir.Delete is used to delete the directory specified by the parameter directoryPathName. This is the equivalent of doing a rmdir in DOS or UNIX. On the Macintosh, it removes a folder.
Dir.Delete will fail if it attempts delete a directory that has files in it.
Carey
Posted: Wed May 02, 2007 9:06 am Post subject: Re: Recursion for deleting
Sorry about the double post, but does anybody have any suggestions? Or have i finally stumped the compsci.ca members?
Cervantes
Posted: Sat May 05, 2007 2:01 pm Post subject: Re: Recursion for deleting
Oh no, we're not stumped. Never!
Here you go. Feel free to ask questions.
Turing:
% don't give a final slash ("/") to the parameter for this procedure procedure del_dir (path :string) var stream :=Dir.Open(path) loop var next :=Dir.Get(stream) exitwhen next ="" ifFile.Exists(path + "/" + next)then% it's a file! File.Delete(path + "/" + next)
% it's a directory! (but don't act on the current or parent directory) elsif next ~="."and next ~=".."then
del_dir (path + "/" + next) Dir.Delete(path + "/" + next) endif endloop Dir.Close(stream) Dir.Delete(path) end del_dir
del_dir ("C:/test")
BenLi
Posted: Sat May 05, 2007 9:46 pm Post subject: RE:Recursion for deleting
potentially able to be put in bad use?
Cervantes
Posted: Sat May 05, 2007 10:51 pm Post subject: RE:Recursion for deleting
Potentially, yes. But it's a very good example of recursion; a good learning experience.
Carey
Posted: Mon May 07, 2007 9:20 am Post subject: Re: Recursion for deleting
Thanks guys. I see what i did wrong now. I knew that stumped comment would get me some replys!!