Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

38
LINES

< > BotCompany Repo | #1035137 // DeleteFilesDialog

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (15894L/95K).

1  
sclass DeleteFilesDialog {
2  
  settable S title = "Delete files";
3  
  new LinkedHashSet<File> filesToDelete;
4  
  
5  
  *() {}
6  
  *(S *title) {}
7  
8  
  selfType wholeDirectory(File dir) {
9  
    if (!isDirectory(dir)) this;
10  
    filesToDelete.addAll(reversed(findAllFiles(dir)));
11  
    filesToDelete.add(dir);
12  
    this;
13  
  }
14  
  
15  
  void show {
16  
    renameSubmitButton("DELETE " + upper(nFiles(filesToDelete)),
17  
      showFormTitled3(title,
18  
        "Files to delete", jscroll(uneditableTextArea(lines(filesToDelete))),
19  
        null, rThread doIt).visualize());
20  
  }
21  
  
22  
  void doIt {
23  
    int successes = 0;
24  
    for (File f : filesToDelete)
25  
      if (deleteFile(f)) {
26  
        print("DELETED: " + f);
27  
        ++successes;
28  
      } else
29  
        print("COULDN'T DELETE: " + f);
30  
    int failures = l(filesToDelete)-successes;
31  
    
32  
    S msg = "Deleted " + nFiles(successes);
33  
    if (failures == 0)
34  
      infoBox(msg);
35  
    else
36  
      messageBox(msg + ", but couldn't delete " + n2(failures));
37  
  }
38  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035137
Snippet name: DeleteFilesDialog
Eternal ID of this version: #1035137/6
Text MD5: a8e017a75955ff2dbe2a43bc3c9f5f62
Transpilation MD5: 2daf486ad2239597f0e96538e5500890
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-31 16:51:36
Source code size: 999 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 163 / 244
Version history: 5 change(s)
Referenced in: [show references]