Page 1 of 1

delete folder

Posted: Sun Dec 02, 2012 3:28 pm
by jmburnod
Hi All,
I have a script to delete a folder, it work well on OSX and IOS but not on windows

Code: Select all

on delFolder pFolder
set the defaultfolder to pFolder
   put the files into tTheFiles
   repeat for each lines tFile in tTheFiles
      put pFolder & "/" & tFile into tPathFile
      delete file tPathFile
   end repeat
   delete folder pFolder
end delFolder
What is wrong ?

Thank
Jean-Marc

Re: delete folder

Posted: Sun Dec 02, 2012 3:41 pm
by Klaus
Hi Jean-Marc,

what does not work: deleting files or the folder?
Did you check "the result"?


Best

Klaus

Re: delete folder

Posted: Sun Dec 02, 2012 4:19 pm
by jmburnod
hi Klaus,
Sorry,
I can't test on windows. It seem "delete folder" don't work (I don't know if all files are deleted)
That is a reply of Simon about this topic
http://forums.runrev.com/phpBB2/viewtop ... =8&t=13466
Best
Jean-Marc

Re: delete folder

Posted: Sun Dec 02, 2012 4:45 pm
by sturgis
One thing you might try is setting the defaultfolder to another location before trying to delete the folder that was created. Worth a try to see if it makes a difference. There is a chance I guess that if you have the defaultfolder still pointing to the inside of the folder in question, the os might be hitting the "the folder is in use.." problem. /shrug. Worth a shot at least.

Code: Select all

   set the defaultfolder to specialfolderpath("documents")
   delete folder pFolder

Re: delete folder

Posted: Sun Dec 02, 2012 4:55 pm
by Klaus
Hi Jean-Marc,

yes, I think strugis hit the nail wit this one:
sturgis wrote:One thing you might try is setting the defaultfolder to another location before trying to delete the folder that was created. Worth a try to see if it makes a difference. There is a chance I guess that if you have the defaultfolder still pointing to the inside of the folder in question, the os might be hitting the "the folder is in use.." problem.
I bet this is the problem, good catch :D

Ususally I do not use the defaultfolder but rather use absolute pathnames. Except for getting its files, of course, but will reset it to the previous defaultfolder after that!
Some kind of "survival strategy" I developed of the last years while coding in Livecode! 8)



Best

Klaus

Re: delete folder

Posted: Sun Dec 02, 2012 7:51 pm
by FourthWorld
Simon only noted that he experienced the same problem, but as here there is no indication of *why* that happened.

Klaus has been using this language a long time, so I can assure you he's not wasting time when he suggests checking "the result" after the "delete folder" command.

Try it and let us know what you find.

I've used "delete folder" under a wide range of circumstances, and while I have had to accommodate the ocassional oddity with Windows, LiveCode itself has always handled it well. I'm sure with just a little diagnostic info we can resolve this for you.

Re: delete folder

Posted: Mon Dec 03, 2012 12:09 pm
by jmburnod
Hi,
Thanks for replys
I made a simple stack to check the results with the suggestion of sturgis
One btn create a new folder with a .txt file in documents folder and an other
delete it.
I can't try it. I haven't got windows
Somebody can test it it on windows ?

Best
Jean-Marc

Re: delete folder

Posted: Mon Dec 03, 2012 3:26 pm
by Simon
Hi Jean-Marc,
That worked for me.
MyNewFolder and it's content was created and deleted.
Nice one Sturgis. I recall I have had troubles with delete folder in the past.

Simon

Re: delete folder

Posted: Mon Dec 03, 2012 3:43 pm
by jmburnod
Hi Simon,
Thank again.
That worked for me
Do you have test it in the "DownloadZipExtractOSX" stack also ?
Just to be sur that was the mistake
Best
Jean-Marc

Re: delete folder

Posted: Mon Dec 03, 2012 4:02 pm
by Simon
Hi Jean-Marc,
In "DownloadZipExtractOSX" I changed:

Code: Select all

--•• delete folder pFolder
on delFolder pFolder
   set the defaultfolder to pFolder
   put the files into tTheFiles
   repeat for each lines tFile in tTheFiles
      put pFolder & "/" & tFile into tPathFile
      delete file tPathFile
   end repeat
--  from TestDeleteFolderWindows.livecode
   if the platform = "Win32"  then
      set the defaultfolder to specialfolderpath("documents") -- add sturgis 021212
   end if
   delete folder pFolder
end delFolder
and it did remove the folder Images50.

Simon

Re: delete folder

Posted: Mon Dec 03, 2012 4:14 pm
by jmburnod
Hi Simon,
Thank again. A mistake less
Best
Jean-Marc