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

27
LINES

< > BotCompany Repo | #1000739 // List current directory with sizes (works, shows "D" or "F" and name and size)

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

Libraryless. Click here for Pure Java version (52L/1K/2K).

!636 (modern)

main {
  psvm {
    String dirToList = ".";
    File d = new File(dirToList);
    if (d.isDirectory()) {
      for (File f : d.listFiles()) {
        boolean isDir = f.isDirectory();
        S line = (isDir ? "D" : "F") + " " + f.getName();
        if (!isDir) {
          long size = f.length();
          S suffix = "B";
          if (size >= 1024*1024) {
            size = (size+1024*1024-1) / (1024*1024);
            suffix = "MB";
          } else if (size >= 1024) {
            size = (size+1024-1) / 1024;
            suffix = "KB";
          }
          line += " (" + size + " " + suffix + ")";
        }
        print(line);
      }
    }
  }
}

Author comment

Began life as a copy of #638

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000739
Snippet name: List current directory with sizes (works, shows "D" or "F" and name and size)
Eternal ID of this version: #1000739/1
Text MD5: b47ee4d1d180b7cca4c6e355915a3f88
Transpilation MD5: c31a3709f4e2b3c449031e6eed52b747
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-27 02:46:04
Source code size: 698 bytes / 27 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 601 / 606
Referenced in: #1000783 - List current directory, sorted by date (newest last)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)