Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: By JaCk | Release 08/19/2017 | https://pastebin.com/cPHrHZ1T | path_express.bat - Display a list of all the paths in the Path var
- @echo off && setlocal EnableDelayedExpansion && (for /f "tokens=1 delims==" %%a in ('set pxv_') do set "%%a=") 2>nul 1>nul
- :: ----------------------------------------
- :: 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
- :: for %%a in ("!path:;=";"!") do (echo/%%~fa)
- :: - Note: On cmd console, use single percentage symbols instead of doubles.
- :: ----------------------------------------
- ::
- ::
- :: ----------------------------------------
- :: Thanks, Sources, and/or [Sourced-]Contributions
- :: ----------------------------------------
- :: !Please Note: Unless noted, no explicit consent to use code was given/received.
- :: !Credited Authors/Parties/Peoples/Persons/Strawmans may be un-aware that they've contributed to this script
- :: ----------------------------------------
- :: + Feature: Prepadded Zeros
- :: ~> Credited Author: jeb - https://stackoverflow.com/users/463115/jeb
- :: * "Lazy Zeros" -- https://stackoverflow.com/a/9430912
- :: * Determine string length -- https://stackoverflow.com/a/19101275
- :: ----------------------------------------
- ::
- ::
- :: ----------------------------------------
- :: Change List
- :: ----------------------------------------
- :: * 08/19/2017 - Removed console one liner as it was causing a crash
- :: - Rewrote some blocks to make the script execute faster, not that it is slow
- :: - Added debug var to dump debug msgs, no need to uncomment debug lines anymore.
- :: - Fixed pxv_flag_padded_zero_numbers. Now it is respected
- ::
- :: + 07/22/2017 - Added Prepadded Zeros,
- :: - Dump script vars upon a normal script exit -- To use, remove the [rem] - (it is not "old code")
- ::
- :: * 07/22/2017 - Changed script comments to, depending on your opinion, [un]clarify certain code blocks and the overall script
- :: + 06/14/2017 - Inital release
- :: ----------------------------------------
- ::
- :::::::::::::::::::::::::::::::::::::::
- ::: :::
- :: ::
- :: Options ::
- :: ::
- ::: :::
- :::::::::::::::::::::::::::::::::::::::
- :: Settings :: Type: Bi-State Boolean :: Accepted Values: [true/undef]
- set "pxv_debug=" rem Default: undef --- To print internal debug msgs
- set "pxv_flag_tcount=true" rem Default: true --- To print the total path count
- set "pxv_flag_numbered_paths=true" rem Default: true --- To print a numbered path list
- set "pxv_flag_padded_zero_numbers=true" rem Default: true --- To print a padded numbered path list
- :: Help Output for Settings
- :: > Setting Flags above will change output behavior, examples below
- :: = Normal -- Prints [Path]
- :: + pxv_flag_tcount -- Prints [[count]] [Path]
- :: + pxv_flag_numbered_paths -- Prints [[count]/[total-count]] [Path]
- :: + pxv_flag_padded_zero_numbers -- Prints [[zero-padded-count]/[total-count]] [Path]
- :::::::::::::::::::::::::::::::::::::::
- ::: :::
- :: ::
- :: Brains ::
- :: ::
- ::: :::
- :::::::::::::::::::::::::::::::::::::::
- :: grab a count of all the items
- echo "!pxv_flag_tcount:~0,1!" | findstr /i "y 1 t" 2>nul 1>nul && for %%a in (
- "!path:;=";"!"
- ) do set /a "pxv_tcnt+=1"
- :: Boolean Check - Display the Padded Numbers
- :: calc string length -- Using str length to "UnLazy" the "Lazy Zeroes"
- :: pxv_padz - Creating a working set of prepadded zeros from total -- deemed "Almost Lazy Zeros"
- echo "!pxv_flag_padded_zero_numbers:~0,1!" | findstr /i "y 1 t" 2>nul 1>nul
- if !errorlevel! equ 0 if !pxv_tcnt! geq 10 (
- set "pxv_Pvar=!pxv_tcnt!#"
- for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
- if "!pxv_Pvar:~%%P,1!" NEQ "" (
- set "pxv_Pvar=!pxv_Pvar:~%%P!"
- set /a "pxv_padz_total+=%%P"
- for /l %%q in (1,1,%%P) do set "pxv_padz=0!pxv_padz!"
- )
- )
- )
- :: Boolean Check - Display the Numbered Path - declare int 0
- echo "!pxv_flag_numbered_paths:~0,1!" | findstr /i "y 1 t" 2>nul 1>nul && set "pxv_cntr=0"
- :: Diplay the paths with the optional total count and/or current count
- :: When reading the do statement, think of an up-side-down tree.
- rem Boolean - counts - [[number]] [Path] -OR- [Path]
- rem Boolean - total counts - [[number]/[total]] [Path]
- rem Boolean - Prepadded "UnLazy Zeroes" - [[padded]/[total]] [Path]
- for %%a in (
- "!path:;=";"!"
- ) do (
- if "%%~fa" neq "" if defined pxv_cntr (
- set /a "pxv_cntr+=1"
- if defined pxv_tcnt (
- if defined pxv_padz (
- set "pxv_zcnt=!pxv_padz!!pxv_cntr!"
- set "pxv_zcnt=!pxv_zcnt:~-%pxv_padz_total%!"
- echo/[!pxv_zcnt!/!pxv_tcnt!] %%~fa
- ) else echo/[!pxv_cntr!/!pxv_tcnt!] %%~fa
- ) else echo/[!pxv_cntr!] %%~fa
- ) else echo/%%~fa
- )
- :: Display the total count if we had not displayed the path counts
- if defined pxv_tcnt if not defined pxv_cntr echo INFO: Total Paths Counted: [!pxv_tcnt!]
- :: gtfo process
- rem dump all script vars and clear all vars
- if defined pxv_debug for /f "tokens=1,* delims==" %%a in ('set pxv_') do echo %%a=%%b
- ( for /f "tokens=1 delims==" %%a in ('set pxv_') do set "%%a=" ) 2>nul 1>nul
- endlocal
Advertisement