slyfox1186

split_windows_path_into_separate_lines.bat

May 5th, 2021 (edited)
561
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @ECHO OFF
  2. COLOR 0A
  3. SETLOCAL
  4.  
  5. REM SPLIT THE WINDOWS PATH VARIABLE INTO SEPARATE LINES
  6. REM USER CAN CHOOSE TO OUTPUT THE RESULTS IN THE CMD WINDOW OR TO A TXT FILE
  7.  
  8. REM YOU MUST DOWNLOAD THE PS1 SCRIPT SHOWN BELOW AND
  9. REM REPLACE THE 'TrimFile' VARIABLE IN THIS SCRIPT WITH THE PATH OF WHERE YOU CREATED IT
  10.  
  11. REM PS1 DOWNLOAD LINK: https://pastebin.com/fz2jG3Zb
  12.  
  13. REM ANY CREATED FILES WILL BE OPENED BY THE PS1 SCRIPT DEFINED BY THE TrimFile VARIABLE
  14.  
  15. :----------------------------------------------------------------------------------
  16.  
  17. REM DETERMINE THE LOCATION OF THE USER'S DOWNLOAD FOLDER AND OPEN CMD WINDOW MAXIMIZED
  18. IF EXIST "%USERPROFILE%\Downloads\" ( PUSHD "%USERPROFILE%\Downloads\" ) ELSE ( PUSHD "%OneDrive%\Downloads\" )
  19. IF NOT "%1"=="MAX" START /MAX CMD /D /C %0 MAX & GOTO :EOF
  20.  
  21. :----------------------------------------------------------------------------------
  22.  
  23. REM POINT THIS VARIABLE TO THE PS1 FILE ON YOUR COMPUTER
  24. SET "TrimFile=REPLACE WITH THE FULL PATH TO THE .PS1 FILE"
  25.  
  26. :----------------------------------------------------------------------------------
  27.  
  28. REM PROMPT THE USER TO DECIDE HOW TO OUTPUT THE RESULTS
  29. ECHO=
  30. ECHO CHOOSE OUTPUT TYPE & ECHO=
  31. ECHO [1] DISPLAY IN CMD
  32. ECHO [2] OUTPUT TO FILE
  33. ECHO [3] EXIT & ECHO=
  34.  
  35. CHOICE /C 123 /N & CLS & ECHO=
  36.  
  37. IF ERRORLEVEL 3 GOTO :EOF
  38. IF ERRORLEVEL 2 GOTO CREATE_TEXT_FILE
  39. IF ERRORLEVEL 1 GOTO DISPLAY_IN_CMD
  40.  
  41. :----------------------------------------------------------------------------------
  42.  
  43. REM PRINT PATH IN CMD WINDOW
  44. :DISPLAY_IN_CMD
  45. REM UNCOMMENT THE NEXT LINE... FOR SOME REASON I HAD TO COMMENT THE COMMAND FOR IT TO DISPLAY PROPERLY
  46. :: ECHO=%PATH:;= & ECHO=%
  47. PAUSE >NUL
  48. GOTO :EOF
  49.  
  50. :----------------------------------------------------------------------------------
  51.  
  52. REM OUTPUT RESULTS TO FILE AND DELETE ANY LEFTOVER FILES FROM PREVIOUS RUNS
  53. :CREATE_TEXT_FILE
  54. IF EXIST "%CD%\Split_Path_Before.txt" DEL /Q "%CD%\Split_Path_Before.txt" "%CD%\Split_Path_After.txt"
  55.  
  56. REM OUTPUT AND SPLIT PATH BY LINE TO TXT FILE
  57. REM AGAIN, UNCOMMENT THE NEXT LINE... FOR SOME REASON I HAD TO COMMENT THE COMMAND FOR IT TO DISPLAY PROPERLY
  58. :: FOR %%G IN ("%PATH:;=";"%") DO ECHO %%G>>%CD%\Split_Path_Before.txt
  59.  
  60. REM RUN POWERSHELL SCRIPTS TO TRIM QUOTES PLUS ANY BLANK LINES AT END OF FILE
  61. POWERSHELL -ExecutionPolicy bypass -NoProfile -NoLogo -File "%TrimFile%" "%CD%\Split_Path_Before.txt"
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×