1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Neat listing

Discussion in 'Support' started by nickles, Jul 21, 2011.

  1. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    I'd like to produce the following output from a directory (_ = space, [] = <>)

    D:\temp\down\check\vb41\app32_________________________[DIR]
    D:\temp\down\check\vb41\data__________________________[DIR]
    D:\temp\down\check\vb41\source________________________[DIR]
    D:\temp\down\check\vb41\Portable-VirtualBox.exe__33.345.345
    Total: 3 directories, 33.345.345 bytes


    How would I do that?

    Could that be done recursively (just giving me the grand total)?

    (Where the heck does the _ _ come from?)
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    nickles wrote:
    | I'd like to produce the following output from a directory:
    |
    | D:\temp\down\check\vb41\app32
    |
    | D:\temp\down\check\vb41\data
    |
    | D:\temp\down\check\vb41\source
    |
    | D:\temp\down\check\vb41\Portable-VirtualBox.exe 33.345.345
    | Total: 3 directories, 33.345.345 bytes
    |
    | How would I do that?
    |
    | Could that be done recursively (just giving me the grand total)?

    To list only directory names:
    *dir/b/ogen/a-d/p/nej/s

    If you want to exclude links (junctions and symlinks):
    *dir/b/ogen/a-d-j/p/nej/s

    Look at the /U2 option to get the totals; probably filtering it through TAIL
    or @EXECSTR to get only the one desired line.
    --
    HTH, Steve
     
  3. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    see below<dir><dir><dir><dir></dir></dir></dir></dir>
     
  4. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    @Steve

    Thanks for the answer, but please mind the exact format of what I hope to obtain (preferably w/o using any third party tool like perl):

    I'd like to get a listing like this:

    Code:
    [FONT=Courier New]D:\temp\down\ubuntu                              [DIR] 
    D:\temp\down\oki_b6250                          60.522 
    D:\temp\down\cream.txt                           1.199 
    D:\temp\down\tux.txt                             1.222 
    D:\temp\down\yongwei.txt                         1.203 
    D:\temp\down\ubuntu\$CONFIG                      [DIR] 
    D:\temp\down\ubuntu\$CONFIG\boottime.kmap.gz     4.744 
    D:\temp\down\ubuntu\$CONFIG\bookmarks.html      10.565 
    D:\temp\down\ubuntu\$CONFIG\prefs.js             4.898 
    [the_grand_total_for_this_and_all_contained_directories]
    [/FONT]
    Btw. Using /u[1|2] in DIR just gives me the one summary line, nothing more.

    p.s. I alread tried lots of options for DIR and PDIR and neither the necessary switches are there (as in the case of the grand total summary line), nor the justification is working ok (as in the case of PDIR with field length prefixes)...

    nickles
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    nickles wrote:
    | @Steve
    |
    | Thanks for the answer, but please mind the exact format of what I
    | hope to obtain (preferably w/o using any third party tool like perl):
    |
    | I'd like to get a listing like this:
    |
    |
    | Code:
    | D:\temp\down\ubuntu [DIR]
    | D:\temp\down\oki_b6250 60.522
    | D:\temp\down\cream.txt 1.199
    | D:\temp\down\tux.txt 1.222
    | D:\temp\down\yongwei.txt 1.203
    | D:\temp\down\ubuntu\$CONFIG [DIR]
    | D:\temp\down\ubuntu\$CONFIG\boottime.kmap.gz 4.744
    | D:\temp\down\ubuntu\$CONFIG\bookmarks.html 10.565
    | D:\temp\down\ubuntu\$CONFIG\prefs.js 4.898
    | [the_grand_total_for_this_and_all_contained_directories]
    | Btw. Using /u[1|2] in DIR just gives me the one summary line, nothing
    | more.
    |
    | p.s. I alread tried lots of options for DIR and PDIR and neither the
    | necessary switches are there (as in the case of the grand total
    | summary line), nor the justification is working ok (as in the case of
    | PDIR with field length prefixes)...

    PDIR does the job for files:
    pdir /(-40fpn zc) /s
    However, it displays the string "<DIR>" unjusttified, 2 characters left of
    where you want it. I had already suggested (for a future version) the
    ability of that string to be justified.
    Another gotcha: To match CMD.EXE, even in PDIR, which has no matching CMD
    command, Rex always displays the widest possible field.

    I see two alternatives:
    1/ Postprocess ach line, using @REPLACE to move the DIR-indicator, and cut
    the size field to your desired width.
    2/ Use a function to create the size/DIR field within PDIR, along the lines
    below:
    - use @IF to determine entry type
    - if DIR, return a fixed string of the right width
    - if file, use @FILESIZE, combined with @FORMATN, to build the exact format
    desired.

    To generate the single summary line, I would use the DIR/U2, and extract the
    one line of interest with @EXECSTR[2,dir/u2/s] (untested!) or with TAIL, and
    append.
     
  6. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    I think you're looking for something like this:

    Code:
    function xsize=`%@format[13,%@if[isdir %1,[DIR],%@filesize[%1,bc]]]`
    
    alias xdir=pdir /(-30fn @xsize
    [*]) /m
    
     
  7. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    r@Charles, Steve

    Thanks for the help of both of you!

    I finally came up with this version:

    Code:
    function xsize = `%@format[13,%@filesize[%1,bc]]`
    alias lrs = `pdir %DIRCMD% /d /s /(-85fpn @xsize
    [*]) & color bright blue on black & echo This directory: %@format[83,%@filesize[%_cwd,bc]] & dir /k /s /u2 | fgrep allo & color white on black`
    
    Interestingly, the formatting in PDIR does not work correctly when using "sp" instead of "fpn" like in:

    Code:
    pdir /d /s /(-85sp zp)
    
    which describes my initial attempt to handle the problem.
    So, the "fpn" and the "function" approach helped a lot!
     
  8. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    I think you need to use -30fpn in the XDIR
    alias though. Otherwise, none of the paths show up.
    You might consider putting the sizes
    first and the names in the second column. Otherwise on paths longer
    than 30 chars the formatting gets messed up.
    Also, by including the /m switch, you
    get totals for each directory instead of one big total at the end.

    So here is my variant:

    Code:
    function xsize=`%@format[13,%@if[isdir %1,[DIR],%@filesize[%1,bc]]]`
    alias xdir=`pdir /(@xsize[*] fpn) %$
    & dir /u2 /k %$`
    
    -Scott

    Charles Dye <> wrote on
    07/21/2011 09:59:48 AM:




    [DIR]


    60.522

    1.199

    1.222

    1.203

    [DIR]


    4.898



     
  9. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    nickles:
    Beware! If DIRCMD in your alias specifies files or directories to be
    cataloged, instead of just additional options, your alias - while it may
    work perfectly in your current build - does not conform to TCC grammar, and
    might fail in the future. Proper grammar requires entities to be cataloged
    after all options are enumerated. OTOH, if it is a COMMAND.COM / CMD.EXE
    leftover, containing only options, it is perfectly fine.
    --
    Steve
     
  10. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    @Scott

    Thanks, I indeed missed the "%$".

    nickles
     

Share This Page