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

48
LINES

< > BotCompany Repo | #1002703 // Show File, Delete File command (master)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1299L/9K/30K).

1  
!752
2  
3  
answer {
4  
  if (!master()) ret null;
5  
  
6  
  if "show file *" exceptionToUser {
7  
    File file = pathToFile(m.unq(0));
8  
    if (!file.exists())
9  
      ret format("File * not found", file.getPath());
10  
    if (file.isDirectory())
11  
      ret "It's a directory";
12  
    ret slackSnippet(loadTextFile(file));
13  
  }
14  
  
15  
  if "delete file *" exceptionToUser {
16  
    File file = pathToFile(m.unq(0));
17  
    if (!file.exists())
18  
      ret format("File * not found", file.getPath());
19  
    if (file.isDirectory())
20  
      ret "It's a directory";
21  
    File delFile = getProgramFile("deleted at " + uniqueNow() + " from " + urlencode(file.getAbsolutePath()));
22  
    if (renameFile(file, delFile))
23  
      ret "OK, backed up as " + delFile.getPath();
24  
    else
25  
      ret format("Hm. Could not rename * to *", file.getPath(), delFile.getPath());
26  
  }
27  
  
28  
  if "copy file * to *" exceptionToUser {
29  
    File file = pathToFile(m.unq(0));
30  
    File dest = pathToFile(m.unq(1));
31  
    if (!file.exists())
32  
      ret format("File * not found", file.getPath());
33  
    if (file.isDirectory())
34  
      ret "It's a directory";
35  
    if (dest.isFile())
36  
      ret format("File * exists", dest.getPath());
37  
    if (dest.isDirectory())
38  
      dest = new File(dest, file.getName());
39  
    copyFile(file, dest);
40  
    ret "OK, copied " + file.getPath() + " to " + dest.getPath();
41  
  }
42  
}
43  
44  
static File pathToFile(S path) {
45  
  if (!path.startsWith("#")) path = "#" + path;
46  
  assertFalse(path.indexOf("..") >= 0);
47  
  ret new File(javaxDataDir(), path);
48  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002703
Snippet name: Show File, Delete File command (master)
Eternal ID of this version: #1002703/1
Text MD5: c752f3c879a0fa9dfde13b47d3b04bfc
Transpilation MD5: adf33a1a9ade137f5c012e4208f808ed
Author: stefan
Category: nl bots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-03-10 18:56:59
Source code size: 1522 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 635 / 934
Referenced in: [show references]