Page 1 of 1

How to delete all text files in the path:specialFolderPath("documents")

Posted: Wed Apr 20, 2022 4:58 pm
by liveCode
How to delete all text files in the path:

Code: Select all

specialFolderPath("documents")

Re: How to delete all text files in the path:specialFolderPath("documents")

Posted: Wed Apr 20, 2022 6:24 pm
by Klaus
Look up:
delete
files("name of folder with the files")
filter

If your text files have the suffix TXT:

Code: Select all

on mouseUp 
   
   ## Save some typing by puttin the path into a variable:
   put specialfolderpath("documents") & "/" into tDocFolder
   ## specialfolderpath() names do not come with a trailing SLASH!
   
   ## Get a list of all files in that folder:
   put files(tDocFolder) into tFiles
   
   ## Exclude all non txt fiels:
   filter tFiles with "*.txt"
   
   ## Now delete all the files in the list of files:
   repeat for each line tFile in tFiles
   
      ## Create full path to the files and delete them:
      delete file (tDocFolder & tFile)
   end repeat
end mouseUp
I recommend to NOT use or test this script on your desktop machine! :D


Best

Klaus

Re: How to delete all text files in the path:specialFolderPath("documents")

Posted: Wed Apr 20, 2022 6:48 pm
by FourthWorld
liveCode wrote:
Wed Apr 20, 2022 4:58 pm
How to delete all text files in the path:

Code: Select all

specialFolderPath("documents")
Respectfully, your good nature as expressed here before suggests to me that you don't actually want to do that. If you were successful you'd eliminate most or all of the user-made content from the machine.

Can you tell us a bit more about what you want to accomplish?

Re: How to delete all text files in the path:specialFolderPath("documents")

Posted: Wed Apr 20, 2022 7:13 pm
by Klaus
Judging from all of his earlier postings I am sure he means MOBILE (Android) without explicitely mentioning it.
We know how miserly he is with more info. :-)