Noél Dubau Posted May 15, 2010 Posted May 15, 2010 Hello, In scriptmaster I found the script DeleteFileOrFolder ; I can't find how to pass jokers to delete all files in the folder without deleting the folder itself. Indeed I saw that there's also a script to create folder, but it would be great if there's a possibility to perform that in only one command. Thanks for your help ! Noël
john renfrew Posted May 15, 2010 Posted May 15, 2010 (edited) I just played around with delete all day If you create a script with the following code it passes the contents of a directory // ListDirectory (fm)Directory) // lists all files in a directory def list = [] //eachFile() returns a list of objects //is.Directory() returns if it is file or directory new File(fm_Directory).eachFile{ if( it.isDirectory() ) { list == list } else { list<< it.absolutePath } } return list it will give you back a list of {everything} all files //edited this now gives system path so the next para is redundant use Filemaker to loop through the list and remove every item that does not have a "." at the end and at the same time add the fm_Directory to the start of each value - am sure someone cleverer than me already might have code for that... Then pass the resultant list to this // Delete( fm_Filelist) // param List() with valid system paths to files // Deletes all the list // Returns 2 if all done, 1 if partially done and 0 if no files deleted files = (fm_Filelist) list = files.split("n") flag2 = 0 flag = 0 list.each { item -> File file = new File("${item}") success = file.delete() if (!success) { flag2 = 1 } else { flag = 1 } } if ( flag2 == 1) { if (flag == 1 ) { return true } else { return false } } else { return 2 } this needs some work obviously but as you have got the list from a function in the first place it should only have legal values anyway Edited May 15, 2010 by Guest
Noél Dubau Posted May 16, 2010 Author Posted May 16, 2010 Hello John Your solution works fine an I thank to to have "played" with that ! It requires also two scripts ; I imagined that it was possible to pass the list as a *.* or at least in my problem an *.jpg Thanks and regards
john renfrew Posted May 16, 2010 Posted May 16, 2010 That must be quite easy to do. It should be possible to pass a file mask and then when the list is built to delete all members in one go. Will have a play tomorrow. Unless someone else wants to....
Recommended Posts
This topic is 5373 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now