May 15, 201015 yr 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
May 15, 201015 yr 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, 201015 yr by Guest
May 16, 201015 yr Author 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
May 16, 201015 yr 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....
Create an account or sign in to comment