1iJaCk

path_express.bat

Jun 14th, 2017
217
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.73 KB | None | 0 0
  1. ::  By JaCk | Release 08/19/2017 | https://pastebin.com/cPHrHZ1T | path_express.bat - Display a list of all the paths in the Path var
  2. @echo off && setlocal EnableDelayedExpansion && (for /f "tokens=1 delims==" %%a in ('set pxv_') do set "%%a=") 2>nul 1>nul
  3.  
  4. ::  ----------------------------------------
  5. ::  Based on this script's authors (JaCk) oneliner -- w00t, making this script useless with excessive lines of code -- why so TL;DR? I has 4ee Tyeme
  6. ::    for %%a in ("!path:;=";"!") do (echo/%%~fa)
  7. ::    - Note: On cmd console, use single percentage symbols instead of doubles.
  8. ::  ----------------------------------------
  9. ::  
  10. ::
  11. ::  ----------------------------------------
  12. ::   Thanks, Sources, and/or [Sourced-]Contributions
  13. ::  ----------------------------------------
  14. ::    !Please Note: Unless noted, no explicit consent to use code was given/received.
  15. ::    !Credited Authors/Parties/Peoples/Persons/Strawmans may be un-aware that they've contributed to this script
  16. ::  ----------------------------------------
  17. ::   + Feature: Prepadded Zeros
  18. ::    ~> Credited Author: jeb - https://stackoverflow.com/users/463115/jeb
  19. ::     * "Lazy Zeros"               -- https://stackoverflow.com/a/9430912
  20. ::     * Determine string length    -- https://stackoverflow.com/a/19101275
  21. ::  ----------------------------------------
  22. ::
  23. ::
  24. ::  ----------------------------------------
  25. ::  Change List
  26. ::  ----------------------------------------
  27. ::  * 08/19/2017 - Removed console one liner as it was causing a crash
  28. ::               - Rewrote some blocks to make the script execute faster, not that it is slow
  29. ::               - Added debug var to dump debug msgs, no need to uncomment debug lines anymore.
  30. ::               - Fixed pxv_flag_padded_zero_numbers.  Now it is respected
  31. ::
  32. ::  + 07/22/2017 - Added Prepadded Zeros,
  33. ::               - Dump script vars upon a normal script exit -- To use, remove the [rem] - (it is not "old code")
  34. ::
  35. ::  * 07/22/2017 - Changed script comments to, depending on your opinion, [un]clarify certain code blocks and the overall script
  36. ::  + 06/14/2017 - Inital release
  37. ::  ----------------------------------------
  38. ::
  39.  
  40.  
  41. :::::::::::::::::::::::::::::::::::::::
  42. :::                                  :::
  43. ::                                    ::
  44. ::               Options              ::
  45. ::                                    ::
  46. :::                                  :::
  47. :::::::::::::::::::::::::::::::::::::::
  48. ::  Settings :: Type: Bi-State Boolean :: Accepted Values: [true/undef]
  49. set "pxv_debug="                        rem  Default: undef  --- To print internal debug msgs
  50. set "pxv_flag_tcount=true"              rem  Default: true   --- To print the total path count
  51. set "pxv_flag_numbered_paths=true"      rem  Default: true   --- To print a numbered path list
  52. set "pxv_flag_padded_zero_numbers=true" rem  Default: true   --- To print a padded numbered path list
  53.  
  54. ::  Help Output for Settings
  55. ::  > Setting Flags above will change output behavior, examples below
  56. ::    = Normal                        -- Prints [Path]
  57. ::    + pxv_flag_tcount               -- Prints [[count]] [Path]
  58. ::    + pxv_flag_numbered_paths       -- Prints [[count]/[total-count]] [Path]
  59. ::    + pxv_flag_padded_zero_numbers  -- Prints [[zero-padded-count]/[total-count]] [Path]
  60.  
  61. :::::::::::::::::::::::::::::::::::::::
  62. :::                                  :::
  63. ::                                    ::
  64. ::                Brains              ::
  65. ::                                    ::
  66. :::                                  :::
  67. :::::::::::::::::::::::::::::::::::::::
  68.  
  69. ::  grab a count of all the items
  70. echo "!pxv_flag_tcount:~0,1!" | findstr /i "y 1 t" 2>nul 1>nul && for %%a in (
  71.     "!path:;=";"!"
  72. ) do set /a "pxv_tcnt+=1"
  73.  
  74.  
  75. ::  Boolean Check - Display the Padded Numbers
  76. ::  calc string length -- Using str length to "UnLazy" the "Lazy Zeroes"
  77. ::  pxv_padz - Creating a working set of prepadded zeros from total -- deemed "Almost Lazy Zeros"
  78. echo "!pxv_flag_padded_zero_numbers:~0,1!" | findstr /i "y 1 t" 2>nul 1>nul
  79. if !errorlevel! equ 0 if !pxv_tcnt! geq 10 (
  80.     set "pxv_Pvar=!pxv_tcnt!#"
  81.  
  82.     for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  83.         if "!pxv_Pvar:~%%P,1!" NEQ "" (
  84.             set "pxv_Pvar=!pxv_Pvar:~%%P!"
  85.             set /a "pxv_padz_total+=%%P"
  86.             for /l %%q in (1,1,%%P) do set "pxv_padz=0!pxv_padz!"
  87.         )
  88.     )
  89. )
  90.  
  91.  
  92. ::  Boolean Check - Display the Numbered Path - declare int 0
  93. echo "!pxv_flag_numbered_paths:~0,1!" | findstr /i "y 1 t" 2>nul 1>nul && set "pxv_cntr=0"
  94.  
  95. ::  Diplay the paths with the optional total count and/or current count
  96. ::  When reading the do statement, think of an up-side-down tree.
  97.    rem  Boolean - counts - [[number]] [Path]  -OR- [Path]
  98.    rem   Boolean - total counts - [[number]/[total]] [Path]
  99.    rem   Boolean - Prepadded "UnLazy Zeroes" - [[padded]/[total]] [Path]
  100. for %%a in (
  101.     "!path:;=";"!"
  102. ) do (
  103.     if "%%~fa" neq "" if defined pxv_cntr (
  104.         set /a "pxv_cntr+=1"
  105.        
  106.         if defined pxv_tcnt (
  107.             if defined pxv_padz (
  108.                 set "pxv_zcnt=!pxv_padz!!pxv_cntr!"
  109.                 set "pxv_zcnt=!pxv_zcnt:~-%pxv_padz_total%!"
  110.                
  111.                 echo/[!pxv_zcnt!/!pxv_tcnt!] %%~fa
  112.             ) else echo/[!pxv_cntr!/!pxv_tcnt!] %%~fa
  113.         ) else echo/[!pxv_cntr!] %%~fa
  114.     ) else echo/%%~fa
  115. )
  116.  
  117.  
  118. ::  Display the total count if we had not displayed the path counts
  119. if defined pxv_tcnt if not defined pxv_cntr echo INFO: Total Paths Counted: [!pxv_tcnt!]
  120.  
  121.  
  122. ::  gtfo process
  123. rem  dump all script vars and clear all vars
  124. if defined pxv_debug for /f "tokens=1,* delims==" %%a in ('set pxv_') do echo %%a=%%b
  125. ( for /f "tokens=1 delims==" %%a in ('set pxv_') do set "%%a=" ) 2>nul 1>nul
  126. endlocal
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment