rlwhitcomb / utilities

Some of my personal utility programs
MIT License
2 stars 0 forks source link

Directory utility is very unfinished #48

Open rlwhitcomb opened 3 years ago

rlwhitcomb commented 3 years ago

A lot of code is there, ported from "C", but it doesn't really do anything at the moment.

Could probably use rewriting a lot because C-like constructs aren't very useful for Java.

rlwhitcomb commented 3 years ago

It would be nice if there were some general-purpose wildcard handling methods somewhere that could be incorporated into DirectoryProcessor, et. al. as well as "Dir", and maybe into FileUtilities also. Come to think about it, CompareFiles could use it, so could Cat, Tree, Calc, and maybe others.... And maybe the FileProcessor stuff should be incorporated into Calc to simplify it, and/or Tester too.... anything that needs to read multiple input files. Then Calc could do "c test/files/e" and load / process a bunch at one time, or "c -lib test/files/lib"

rlwhitcomb commented 2 years ago

The "-wide" setting should do columnar output similarly to "os" program (data goes down the column with extra fields in the first few columns) then to the next column and down, etc. (in contrast to "dir /w" which puts values across the rows first (which is very hard to find stuff in alphabetical order)).

rlwhitcomb commented 2 years ago

Windows 10 list of "DIR" options, just for reference (i.e., no commitment to implement any or all of these features):

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
  [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

  [drive:][path][filename]
              Specifies drive, directory, and/or files to list.

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  Hidden files               A  Files ready for archiving
               S  System files               I  Not content indexed files
               L  Reparse Points             -  Prefix meaning not
  /B          Uses bare format (no heading information or summary).
  /C          Display the thousand separator in file sizes.  This is the
              default.  Use /-C to disable display of separator.
  /D          Same as wide but files are list sorted by column.
  /L          Uses lowercase.
  /N          New long list format where filenames are on the far right.
  /O          List by files in sorted order.
  sortorder    N  By name (alphabetic)       S  By size (smallest first)
               E  By extension (alphabetic)  D  By date/time (oldest first)
               G  Group directories first    -  Prefix to reverse order
  /P          Pauses after each screenful of information.
  /Q          Display the owner of the file.
  /R          Display alternate data streams of the file.
  /S          Displays files in specified directory and all subdirectories.
  /T          Controls which time field displayed or used for sorting
  timefield   C  Creation
              A  Last Access
              W  Last Written
  /W          Uses wide list format.
  /X          This displays the short names generated for non-8dot3 file
              names.  The format is that of /N with the short name inserted
              before the long name. If no short name is present, blanks are
              displayed in its place.
  /4          Displays four-digit years

Switches may be preset in the DIRCMD environment variable.  Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.
rlwhitcomb commented 2 years ago

I think I need to use Files.walkFileTree in order to detect symbolic links ... the File method is not working.

rlwhitcomb commented 2 years ago

Need to prepass through files, even without sorting or wide in order to regularize the listing with a lot of over-long owner names, like this:

         4.00K NT AUTHORITY\SYSTEM Nov  8  2018 inetpub
         8.00K QRLANCHOR\mphowner Jun 30 12:38 Jenkins
             0 BUILTIN\Administrators Oct  9  2019 Lexmark
         4.00K BUILTIN\Administrators Aug 13  2020 LocalBackup
             0 QRLANCHOR\lhmarbol Jan  4  2019 Logs
             0 BUILTIN\Administrators Sep 18  2019 MinGW
 RH          0 Sep 13  2018 MSOCache
         96.0K BUILTIN\Administrators Nov  8  6:29 OpenArrow
         32.0K BUILTIN\Administrators Nov  9  2018 OpenArrow123C
rlwhitcomb commented 2 years ago

Need an option for AM/PM format of times instead of 24-hour format.

rlwhitcomb commented 2 years ago

Also an option to skip listing owner/group (esp. for Windows where you don't typically worry about this).

rlwhitcomb commented 2 years ago

One thing I noticed on Linux when a file name has embedded spaces:

drwxr-xr-x  3 jenkins jenkins 4096 Aug 11 20:34  Build_WebHelp_Beta
drwxr-xr-x  3 jenkins jenkins 4096 Aug 29 16:23 'Commit Notification'

Notice the extra space on the first line that is taken up by the single quote on the second line.

rlwhitcomb commented 1 year ago

One BIG problem is that Java automatically expands wildcards, so they don't make it to our wildcard filter, so we never see the actual wildcard pattern (for use, for instance, in subdirectories). I don't know how to fix this....

rlwhitcomb commented 1 year ago

One thing I noticed on Linux when a file name has embedded spaces:

drwxr-xr-x  3 jenkins jenkins 4096 Aug 11 20:34  Build_WebHelp_Beta
drwxr-xr-x  3 jenkins jenkins 4096 Aug 29 16:23 'Commit Notification'

Notice the extra space on the first line that is taken up by the single quote on the second line.

rlwhitcomb commented 1 year ago

SOOOO ... I think the wildcard handling is a show-stopper. I can't figure out any way to get the raw command line, so implementing d *.class -s will be impossible.

My current thinking, then, is to use "golang" instead, which seems to have command-line handling much like "C", where it breaks on spaces, but doesn't automatically recognize wildcards.... Maybe. The research continues, but here's a start: https://golangdocs.com/command-line-arguments-in-golang

rlwhitcomb commented 1 year ago

I think the solution is to switch to using "go" to write the "d" utility. It appears that there are plenty of library functions to produce the results I want. Will require a lot of research into building projects in "go", integrating into the Ant build process, etc.

rlwhitcomb commented 1 year ago

At least with "go" I can quote the wildcard arguments and what gets passed to the program is the unquoted values:

% ./hello hello*
[./hello hello hello.go]
% ./hello '*.*'
[./hello *.*]