Delete folder syntax
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Delete folder syntax
I can create folders in the Documents folder and read and write to files in them. However, I am having trouble deleting a folder and I can't seem to get the syntax right.
Could someone please just give me a line of code that deletes a folder in iOS?
Thanks
Don
Could someone please just give me a line of code that deletes a folder in iOS?
Thanks
Don
Re: Delete folder syntax
Hi Don,
...
delete folder XYZ
...
should do, BUT the folder needs to be EMPTY before you can delete it!
So you will have to delete all files inside of it first!
Best
Klaus
...
delete folder XYZ
...
should do, BUT the folder needs to be EMPTY before you can delete it!
So you will have to delete all files inside of it first!
Best
Klaus
Re: Delete folder syntax
Hi Don,
There is a lesson to get the list of files in folder and subfolders
http://www.runrev.com/developers/lesson ... d-folders/
Best regards
Jean-Marc
There is a lesson to get the list of files in folder and subfolders
http://www.runrev.com/developers/lesson ... d-folders/
Best regards
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 10063
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Delete folder syntax
Also, the directory cannot be in use by your app or any other at the time you delete it. This has bitten me once, but simply setting the default folder to something else takes care of it.Klaus wrote:Hi Don,
...
delete folder XYZ
...
should do, BUT the folder needs to be EMPTY before you can delete it!
So you will have to delete all files inside of it first!
If you have any issues with deleting a folder, or pretty much any file I/O issue, it can be helpful to include the sysError function in your reporting, e.g.:
Code: Select all
delete folder tMyPath
if the result is not empty then
answer the result & "("& sysError() &")"
end if
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Delete folder syntax
Thanks guys
I was aware that in iOS only an empty folder could be deleted, and I was sure that was the case. However, your posts prompted me to look a bit deeper and I found there was a file in there after all. So, problem solved.
Cheers
Don
I was aware that in iOS only an empty folder could be deleted, and I was sure that was the case. However, your posts prompted me to look a bit deeper and I found there was a file in there after all. So, problem solved.
Cheers
Don
Re: Delete folder syntax
So is the best practice to return the files and then delete them one by one in a repeat loop and then delete the empty folder? Such as.... Seems like a lot of work just to delete a folder with some files in it. Is there an easier way?
By the way this script does work I tested it.
on mouseUp
if the environment is not mobile then
put "/Users/fireworxsoftware/Desktop/The Files/library" into TPath1
put tPath1 & "/MyFolder" into tPath2
else
put specialFolderPath("Library") into tPath1
put tPath1 & "/MyFolder" into tPath2
end if
set the defaultfolder to tPath2
put the files into tMyList
repeat with x = 1 to the number of lines of tMylist
put line x of tMyList into tFile
delete file tPath2 & "/" & tFile
end repeat
delete folder tPath1 & "/MyFolder"
end mouseUp
By the way this script does work I tested it.
on mouseUp
if the environment is not mobile then
put "/Users/fireworxsoftware/Desktop/The Files/library" into TPath1
put tPath1 & "/MyFolder" into tPath2
else
put specialFolderPath("Library") into tPath1
put tPath1 & "/MyFolder" into tPath2
end if
set the defaultfolder to tPath2
put the files into tMyList
repeat with x = 1 to the number of lines of tMylist
put line x of tMyList into tFile
delete file tPath2 & "/" & tFile
end repeat
delete folder tPath1 & "/MyFolder"
end mouseUp