SHARE
TWEET

randomizeFiles.bat

rerere284 Jun 18th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @ECHO OFF
  2. setlocal EnableDelayedExpansion
  3. ::save the current directory it is set to
  4. ::so we can put it back later
  5. set "oldCD=%cd%"
  6. ::if program is started with inputs,
  7. ::run the commandline version of the program.
  8. if NOT "%~1"=="" goto commandLine
  9. ::if the program is NOT started with inputs,
  10. ::go to the normal version of the program.
  11. goto beginning
  12.  
  13.  
  14.  
  15. ::zlib License
  16. ::
  17. ::(C) 2019 rerere284
  18. ::(some functions from stackoverflow where noted)
  19. ::
  20. ::This software is provided 'as-is', without any express or implied
  21. ::warranty.  In no event will the authors be held liable for any damages
  22. ::arising from the use of this software.
  23. ::
  24. ::Permission is granted to anyone to use this software for any purpose,
  25. ::including commercial applications, and to alter it and redistribute it
  26. ::freely, subject to the following restrictions:
  27. ::
  28. ::1. The origin of this software must not be misrepresented; you must not
  29. ::   claim that you wrote the original software. If you use this software
  30. ::   in a product, an acknowledgment in the product documentation would be
  31. ::   appreciated but is not required.
  32. ::2. Altered source versions must be plainly marked as such, and must not be
  33. ::   misrepresented as being the original software.
  34. ::3. This notice may not be removed or altered from any source distribution.
  35.  
  36. :disclaimer
  37. call :echoWrap This program is licensed under the zlib license. This program is intended for randomizing media files in games. Please be careful. Randomizing IMPORTANT FOLDERS or YOUR ENTIRE COMPUTER is NOT RECOMMENDED. Running the program again in the same location will run the undo function. The undo function DELETES the files created by the program and restores the old files if they are present in the folder.
  38. EXIT /B 0
  39.  
  40.  
  41.  
  42.  
  43. :beginning
  44. ::temporarily endlocal so we can write a '!'
  45. endlocal
  46. echo/
  47. call :header Welcome to the file randomizer!
  48. setlocal EnableDelayedExpansion
  49. echo by rerere284
  50. echo/
  51. call :disclaimer
  52. echo/
  53. echo/
  54.  
  55. ::  TODO:
  56. ::disclaimer
  57. ::youtube-dl support???
  58.    ::a bit feature-creep-y
  59.  
  60.  
  61.  
  62. ::  DONE:
  63. ::undo option
  64.    ::auto detect that it has been done before
  65.        ::files prefixed with [oldfile] of type filetype
  66.    ::option to either undo or back out to main menu
  67. ::recursive option
  68.    ::dir is always recursive
  69.    ::more of a 'non-recursive option'
  70.    ::non recursive option might be pointless
  71.    ::might help with minecraft resource packs
  72.    ::dir's /S might do this?
  73.    ::yep
  74. ::option selection
  75.    ::welcome to the file randomizer!
  76.    ::(enter file locations etc.)
  77.    ::check if undo should be offered
  78.        ::offer undo or continue program
  79.        ::either way, display menu for recursive option
  80.    ::echo 1) Option 1
  81.    ::echo 2) Option 2
  82.    ::set /p op=Type option:
  83.    ::if "%op%"=="1" goto op1
  84.    ::if "%op%"=="2" goto op2
  85. ::progress bar
  86.    ::some feature creep
  87. ::run via command line
  88. ::tell people they can drag files into the window to paste the path
  89. ::sanity check if too many files are going to get randomized
  90. ::add sufficient notes to the code
  91. ::inputted paths can lack quotes and still have spaces
  92.  
  93.  
  94. ::get path of old files from user
  95. ::and check that the path is valid
  96. call :enterOld
  97. call :checkOld
  98.  
  99. ::ask user if they want the program to check recursively
  100. call :offerRecurse
  101.  
  102. ::get file type of files from user
  103. ::and check that files of that type exist
  104. call :enterType
  105. call :checkType
  106.  
  107. ::check if the program has already been run
  108. ::can't run the program on the same files twice
  109. ::if the program has been run, go ask the user if they want to undo
  110. set shouldUndo=false
  111. call :checkUndo
  112. if !shouldUndo!==true (
  113.     goto doUndo
  114. )
  115.  
  116. ::if the program hasn't been run,
  117. ::get path of new files from user
  118. ::and check that the path is valid
  119. call :enterNew
  120. call :checkNew
  121.  
  122. ::we have all our data, start the program
  123. goto start
  124.  
  125.  
  126.  
  127.  
  128. :enterNew
  129. echo/
  130. echo input or drag in folder containing new files to swap in:
  131. set /p NEWF=folder:
  132. ::replace quotes in path with nothing
  133. set NEWF=%NEWF:"=%
  134. EXIT /B 0
  135.  
  136. :checkNew
  137. if not exist "%NEWF%" (
  138.     echo directory %NEWF% not found
  139.     call :enterNew
  140.     call :checkNew
  141. )
  142. if "%NEWF%"=="%OLDF%" (
  143.     echo please choose a different directory than the one you picked previously.
  144.     call :enterNew
  145.     call :checkNew
  146. )
  147. EXIT /B 0
  148.  
  149. :enterOld
  150. echo/
  151. echo input or drag in folder containing old files to swap out:
  152. set /p OLDF=folder:
  153. ::replace quotes in path with nothing
  154. set OLDF=%OLDF:"=%
  155. EXIT /B 0
  156.  
  157. :checkOld
  158. if not exist "%OLDF%" (
  159.     echo directory %OLDF% not found
  160.     call :enterOld
  161.     call :checkOld
  162. )
  163. EXIT /B 0
  164.  
  165. :enterType
  166. echo/
  167. echo input file type being handled (png, mp3, map...):
  168. set /p filetype=type:
  169. ::replace dots in filetype with nothing
  170. set filetype=%filetype:.=%
  171. EXIT /B 0
  172.  
  173. :checkType
  174. ::check that files of that type exist there
  175. cd /d !OLDF!
  176. dir /a-d %recurse%*.%filetype% >nul 2>&1 || (
  177.     echo could't find file of type %filetype% in %OLDF%
  178.     call :enterType
  179.     call :checkType
  180. )
  181. cd /d "%oldCD%"
  182. EXIT /B 0
  183.  
  184. :offerRecurse
  185. echo/
  186. echo Do you want to check recursively?
  187. echo This will check inside of all folders within the directory.
  188. :askRecurse
  189. set /p undoOp=(Y/N):
  190. if !undoOp!==y goto doRecurseChecks
  191. if !undoOp!==Y goto doRecurseChecks
  192. if !undoOp!==n EXIT /B 0
  193. if !undoOp!==N EXIT /B 0
  194. goto askRecurse
  195. :doRecurseChecks
  196. set "recurse=/S "
  197. echo will now do checks recursively, checking inside all folders within the directory.
  198. EXIT /B 0
  199.  
  200.  
  201. :start
  202.  
  203.  
  204.  
  205. ::you can tell by the comments how much trouble this gave me
  206.  
  207.  
  208. ::for each file in NEWF of the type filetype
  209.    ::add it to a list
  210. set /a numberr=0
  211. cd /d %NEWF%
  212. for /f "delims=" %%f in ('dir /b %recurse%*.%filetype%') do (
  213.     set /a numberr=!numberr!+1
  214.     set list[!numberr!]=%%~ff
  215.    REM set listVar=list[!numberr!]
  216.    REM echo numberr !numberr!
  217.    REM call echo list[!numberr!] %%!listVar!%%
  218.    REM call echo list[!numberr!] %%list[!numberr!]%%
  219. )
  220. cd /d "%oldCD%"
  221.  
  222. ::for /l %%a in (1, 1, !numberr!) do (
  223.    ::echo %%a
  224.    ::echo !list[%%a]!
  225. ::)
  226.  
  227. ::set current directory to where dir command is being run
  228. cd /d %OLDF%
  229. :: Count the number of files
  230. set oN=0
  231. for /f "delims=" %%f in ('dir /b %recurse%*.%filetype%') do set /A oN+=1
  232.  
  233. :: if there are a lot of files, double check
  234. if %oN% gtr 100 (
  235.    rem sanity check due to number of files
  236.     echo Are you sure you want to randomize %~1 .%filetype% files in %OLDF% ?
  237.     :askSanity
  238.     set /p undoOp=(Y/N):
  239.     if !undoOp!==y goto doneSanityCheck
  240.     if !undoOp!==Y goto doneSanityCheck
  241.     if !undoOp!==n (
  242.        rem reset current directory and exit
  243.         cd /d "%oldCD%"
  244.         EXIT /B %ERRORLEVEL%
  245.     )
  246.     if !undoOp!==N (
  247.        rem reset current directory and exit
  248.         cd /d "%oldCD%"
  249.         EXIT /B %ERRORLEVEL%
  250.     )
  251.     goto askSanity
  252.     :doneSanityCheck
  253. )
  254.  
  255. ::for each file in OLDF of the type filetype
  256.    ::set a variable to the name of that file
  257.    ::prepend the OLDF file name with some weird string
  258.    ::pick a random file from the NEWF list
  259.    ::copy that file to OLDF, naming it the name of the file
  260. set oNN=0
  261. for /f "delims=" %%f in ('dir /b %recurse%*.%filetype%') do (
  262.     set TEMPNAME=%%~nf
  263.     ren "%%f" "[oldfile]!TEMPNAME!.%filetype%"
  264.        rem echo ren !TEMPNAME!.%filetype%
  265.     set /a "rand=(numberr*!random!)/32768+1"
  266.        rem echo rand !rand!
  267.     call set thisFile=%%list[!rand!]%%
  268.        rem echo thisFile !thisFile!
  269.        rem call echo list[!rand!] %%list[!rand!]%%
  270.        rem echo TEMPNAME !TEMPNAME!
  271.     copy /-Y "!thisFile!" "!TEMPNAME!.%filetype%" >nul
  272.        rem echo copy /-Y "!thisFile!" "!TEMPNAME!.%filetype%"
  273.     set /A oI=100*oNN/oN
  274.     call :drawProgressBar oI "randomizing files..."
  275.     set /A oNN+=1
  276. )
  277. cd /d "%oldCD%"
  278. call :drawProgressBar 100 "randomizing files..."
  279. echo/
  280.  
  281.  
  282.  
  283. echo/
  284. echo/
  285. ::temporarily endlocal so we can print '!'
  286. endlocal
  287. call :header Files randomized! Enjoy your randomization!
  288. setlocal EnableDelayedExpansion
  289. echo/
  290. echo old filenames have been prefixed with [oldfile]
  291. echo if you want this undone, run this program again with the same parameters.
  292.  
  293.  
  294. pause >nul
  295. EXIT /B %ERRORLEVEL%
  296.  
  297.  
  298. :checkUndo
  299. cd /d %OLDF%
  300. rem check for files with the prefix [oldfile] of type filetype
  301. dir /a-d %recurse%[oldfile]*.!filetype! >nul 2>&1 && set shouldUndo=true
  302. cd /d "%oldCD%"
  303. EXIT /B 0
  304.  
  305.  
  306. :doUndo
  307. echo/
  308. echo Randomized files of type %filetype% detected. Unable to randomize further.
  309. echo Undo randomization? Current random files will be replaced by old files.
  310. :askUndo
  311. set /p undoOp=(Y/N):
  312. if !undoOp!==y goto continueUndo
  313. if !undoOp!==Y goto continueUndo
  314. if !undoOp!==n goto beginning
  315. if !undoOp!==N goto beginning
  316. goto askUndo
  317. :continueUndo
  318.  
  319.  
  320. ::for each file in OLDF with the prefix
  321.    ::set a variable to the name of that file
  322.    ::assemble directory of version without prefix
  323.    ::if that exists
  324.        ::delete that
  325.    ::rename this file to be version without prefix
  326. cd /d %OLDF%
  327. rem Count the number of files
  328. set oN=0
  329. for /f "delims=" %%f in ('dir /b %recurse%[oldfile]*.%filetype%') do set /A oN+=1
  330. set oNN=0
  331. for /f "delims=" %%f in ('dir /b %recurse%[oldfile]*.%filetype%') do (
  332.        REM endlocal
  333.        REM setlocal DisableDelayedExpansion
  334.     set TEMPNAME=%%~nf
  335.     set NEWPATH=%%~dpf
  336.        REM endlocal
  337.        REM setlocal EnableDelayedExpansion
  338.     set NEWNAME=!TEMPNAME:~9!.%filetype%
  339.        REM set NEWPATH=!NEWPATH:[oldfile]=!
  340.     set NEWPATH=!NEWPATH!!NEWNAME!
  341.     if exist !NEWPATH! (
  342.            REM echo at %%f
  343.            REM echo !NEWNAME! exists
  344.         del /f "!NEWPATH!"
  345.     )
  346.    REM ren "%%f" "!TEMPNAME:[oldfile]=!.%filetype%"
  347.     ren "%%f" "!NEWNAME!"
  348.    
  349.     set /A oI=100*oNN/oN
  350.     call :drawProgressBar oI "unrandomizing files..."
  351.     set /A oNN+=1
  352. )
  353. cd /d "%oldCD%"
  354. call :drawProgressBar 100 "unrandomizing files..."
  355. echo/
  356.  
  357.  
  358.  
  359. endlocal
  360. call :header Files unrandomized! Enjoy your organization!
  361.  
  362. rem Files unrandomized! Enjoy your ____ization!
  363. rem unrandimization
  364. rem organization
  365. rem catagorization
  366. rem normalization
  367. rem realization
  368. rem recatagorization
  369. rem personalization
  370. rem sanitization
  371. rem naturalization
  372. rem optimization
  373.  
  374.  
  375. rem weird bug, whatever, it works
  376. call pause >nul
  377. pause >nul
  378. EXIT /B %ERRORLEVEL%
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386. :commandLine
  387. ::commandline version of the program
  388.  
  389. ::if the first input is 'h', display help and exit
  390. if "%~1"=="/h" goto commandHelp
  391. if "%~1"=="/H" goto commandHelp
  392. if "%~1"=="-h" goto commandHelp
  393. if "%~1"=="-H" goto commandHelp
  394. if "%~1"=="/?" goto commandHelp
  395.  
  396.  
  397.  
  398. set paramUndo=false
  399. set paramRecurse=false
  400. set paramSilent=false
  401. FOR %%A IN (%*) DO (
  402.    rem variable to keep track of what the current variable is
  403.     set wasParam=false
  404.    
  405.     rem check for the undo param
  406.     if "%%A"=="/u" set "paramUndo=true" & set wasParam=true
  407.     if "%%A"=="/U" set "paramUndo=true" & set wasParam=true
  408.     if "%%A"=="-u" set "paramUndo=true" & set wasParam=true
  409.     if "%%A"=="-U" set "paramUndo=true" & set wasParam=true
  410.    
  411.     rem check for the recurse param
  412.     if "%%A"=="/r" set "paramRecurse=true" & set wasParam=true
  413.     if "%%A"=="/R" set "paramRecurse=true" & set wasParam=true
  414.     if "%%A"=="-r" set "paramRecurse=true" & set wasParam=true
  415.     if "%%A"=="-R" set "paramRecurse=true" & set wasParam=true
  416.    
  417.     rem check for the silent param
  418.     if "%%A"=="/s" set "paramSilent=true" & set wasParam=true
  419.     if "%%A"=="/S" set "paramSilent=true" & set wasParam=true
  420.     if "%%A"=="-s" set "paramSilent=true" & set wasParam=true
  421.     if "%%A"=="-S" set "paramSilent=true" & set wasParam=true
  422.    
  423.     rem if the current variable was not a param
  424.    rem that means it is a path or a filetype
  425.    rem set the first one of those that is not defined
  426.     if !wasParam!==false (
  427.         if not defined NEWF (
  428.             set NEWF=%%A
  429.             if not exist "!NEWF!" (
  430.                 echo directory !NEWF! not found
  431.                 EXIT /B 1
  432.             )
  433.         ) else (
  434.             if not defined OLDF (
  435.                 set OLDF=%%A
  436.                 if not exist "!OLDF!" (
  437.                     echo directory !OLDF! not found
  438.                     EXIT /B 1
  439.                 )
  440.             ) else (
  441.                 if not defined filetype (
  442.                     if !paramRecurse!==true set "recurse=/S "
  443.                     set filetype=%%A
  444.                     cd /d !OLDF!
  445.                     dir /a-d !recurse!*.!filetype! >nul 2>&1 || (
  446.                         echo could't find file of type !filetype! in !OLDF!
  447.                         cd /d "%oldCD%"
  448.                         EXIT /B 1
  449.                     )
  450.                     cd /d "%oldCD%"
  451.                 ) else (
  452.                     echo extra param %%A
  453.                 )
  454.             )
  455.         )
  456.     )
  457. )
  458.  
  459.  
  460.  
  461.  
  462. if not defined NEWF (
  463.     echo pathToNewFiles not given
  464.     EXIT /B 1
  465. )
  466. if not defined OLDF (
  467.     echo pathToOldFiles not given
  468.     EXIT /B 1
  469. )
  470. if not defined filetype (
  471.     echo fileType not given
  472.     EXIT /B 1
  473. )
  474.  
  475. ::check if you should undo instead of running normally
  476. ::by checking if the program has been run before
  477. set shouldUndo=false
  478. call :checkUndo
  479.  
  480. ::if paramUndo and shouldUndo don't match, the program exits
  481. if !paramUndo!==false (
  482.     if !shouldUndo!==true (
  483.         echo randomized files of type !filetype! already present in !OLDF!
  484.         EXIT /B 1
  485.     )
  486.    
  487.     rem for each file in NEWF of the type filetype
  488.        rem add it to a list
  489.     set /a numberr=0
  490.     cd /d "!NEWF!"
  491.     for /f "delims=" %%f in ('dir /b !recurse!*.!filetype!') do (
  492.         set /a numberr=!numberr!+1
  493.         set list[!numberr!]=%%~ff
  494.     )
  495.     cd /d "%oldCD%"
  496.    
  497.     rem for each file in OLDF of the type filetype
  498.        rem set a variable to the name of that file
  499.        rem prepend the OLDF file name with some weird string
  500.        rem pick a random file from the NEWF list
  501.        rem copy that file to OLDF, naming it the name of the file
  502.     cd /d "!OLDF!"
  503.    rem Count the number of files
  504.     set oN=0
  505.     for /f "delims=" %%f in ('dir /b !recurse!*.!filetype!') do set /A oN+=1
  506.     set oNN=0
  507.    
  508.    
  509.     cd /d "!OLDF!"
  510.     for /f "delims=" %%f in ('dir /b !recurse!*.!filetype!') do (
  511.         set TEMPNAME=%%~nf
  512.         set OLDPATH=%%~ff
  513.         ren "%%f" "[oldfile]!TEMPNAME!.!filetype!"
  514.         set /a "rand=(numberr*!random!)/32768+1"
  515.         call set thisFile=%%list[!rand!]%%
  516.         copy /-Y "!thisFile!" "!OLDPATH!" >nul
  517.         set /A oI=100*oNN/oN
  518.         if !paramSilent!==false (
  519.             call :drawProgressBar oI "randomizing files..."
  520.         )
  521.         set /A oNN+=1
  522.     )
  523.     cd /d "%oldCD%"
  524.    
  525.    
  526.     if !paramSilent!==false (
  527.         call :drawProgressBar 100 "randomizing files..."
  528.         echo/
  529.         echo/
  530.         echo/
  531.         endlocal
  532.         call :header Files randomized! Enjoy your randomization!
  533.         setlocal EnableDelayedExpansion
  534.         echo/
  535.         echo old filenames have been prefixed with [oldfile]
  536.         echo if you want this undone, run this program again with the same parameters.
  537.     )
  538.     EXIT /B %ERRORLEVEL%
  539.  
  540. ) else (
  541.    
  542.     if !shouldUndo!==false (
  543.         echo randomized files of type !filetype! not present in !OLDF!
  544.         EXIT /B 1
  545.     )
  546.    
  547.     cd /d "!OLDF!"
  548.    rem Count the number of files
  549.     set oN=0
  550.     for /f "delims=" %%f in ('dir /b !recurse![oldfile]*.!filetype!') do set /A oN+=1
  551.    
  552.     rem for each file in OLDF with the prefix
  553.    rem set a variable to the name of that file
  554.    rem assemble directory of version without prefix
  555.    rem if that exists
  556.        rem delete that
  557.        rem rename this file to be version without prefix
  558.     set oNN=0
  559.     for /f "delims=" %%f in ('dir /b !recurse![oldfile]*.!filetype!') do (
  560.         set TEMPNAME=%%~nf
  561.         set NEWPATH=%%~dpf
  562.         set NEWNAME=!TEMPNAME:~9!.!filetype!
  563.         set NEWPATH=!NEWPATH!!NEWNAME!
  564.         if exist !NEWPATH! (
  565.             del /f "!NEWPATH!"
  566.         )
  567.         ren "%%f" "!NEWNAME!"
  568.        
  569.         set /A oI=100*oNN/oN
  570.         if !paramSilent!==false (
  571.             call :drawProgressBar oI "unrandomizing files..."
  572.         )
  573.         set /A oNN+=1
  574.     )
  575.     cd /d "%oldCD%"
  576.     if !paramSilent!==false (
  577.        rem draw progress bar at 100% since it is done
  578.         call :drawProgressBar 100 "unrandomizing files..."
  579.         echo/
  580.         endlocal
  581.         call :header Files unrandomized! Enjoy your organization!
  582.     )
  583.     EXIT /B %ERRORLEVEL%
  584.    
  585. )
  586.  
  587.  
  588. EXIT /B %ERRORLEVEL%
  589.  
  590.  
  591.  
  592.  
  593.  
  594. :commandHelp
  595. echo Randomizes a set of files to be another provided set of files of the same type.
  596. echo/
  597. echo Usage: randomizeFiles.bat [options] "pathToNewFiles" "pathToOldFiles" fileType
  598. echo/
  599. echo   -h show this help
  600. echo   -u undo a randomization
  601. echo   -r check recursively
  602. echo   -s silent mode
  603. echo/
  604. echo/
  605. EXIT /B %ERRORLEVEL%
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621. :header
  622. ::print inputted text between two bars
  623. ECHO =================================================
  624. ECHO %*
  625. ECHO =================================================
  626. EXIT /B 0
  627.  
  628.  
  629.  
  630. REM https://stackoverflow.com/questions/21108380/coding-a-real-time-progress-bar-in-batch
  631. :drawProgressBar value [text]
  632. if "%~1"=="" goto :eof
  633. if not defined pb.barArea call :initProgressBar
  634. setlocal enableextensions enabledelayedexpansion
  635. set /a "pb.value=%~1 %% 101", "pb.filled=pb.value*pb.barArea/100", "pb.dotted=pb.barArea-pb.filled", "pb.pct=1000+pb.value"
  636. set "pb.pct=%pb.pct:~-3%"
  637. if "%~2"=="" ( set "pb.text=" ) else (
  638.     set "pb.text=%~2%pb.back%"
  639.     set "pb.text=!pb.text:~0,%pb.textArea%!"
  640. )
  641. <nul set /p "pb.prompt=[!pb.fill:~0,%pb.filled%!!pb.dots:~0,%pb.dotted%!][ %pb.pct% ] %pb.text%!pb.cr!"
  642. endlocal
  643. EXIT /B 0
  644.  
  645. REM https://stackoverflow.com/questions/21108380/coding-a-real-time-progress-bar-in-batch
  646. :initProgressBar [fillChar] [dotChar]
  647. if defined pb.cr call :finalizeProgressBar
  648. for /f %%a in ('copy "%~f0" nul /z') do set "pb.cr=%%a"
  649. if "%~1"=="" ( set "pb.fillChar=#" ) else ( set "pb.fillChar=%~1" )
  650. if "%~2"=="" ( set "pb.dotChar=." ) else ( set "pb.dotChar=%~2" )
  651. set "pb.console.columns="
  652. for /f "tokens=2 skip=4" %%f in ('mode con') do if not defined pb.console.columns set "pb.console.columns=%%f"
  653. set /a "pb.barArea=pb.console.columns/2-2", "pb.textArea=pb.barArea-9"
  654. set "pb.fill="
  655. setlocal enableextensions enabledelayedexpansion
  656. for /l %%p in (1 1 %pb.barArea%) do set "pb.fill=!pb.fill!%pb.fillChar%"
  657. set "pb.fill=!pb.fill:~0,%pb.barArea%!"
  658. set "pb.dots=!pb.fill:%pb.fillChar%=%pb.dotChar%!"
  659. set "pb.back=!pb.fill:~0,%pb.textArea%!
  660. set "pb.back=!pb.back:%pb.fillChar%= !"
  661. endlocal & set "pb.fill=%pb.fill%" & set "pb.dots=%pb.dots%" & set "pb.back=%pb.back%"
  662. EXIT /B 0
  663.  
  664. REM https://stackoverflow.com/questions/21108380/coding-a-real-time-progress-bar-in-batch
  665. :finalizeProgressBar [erase]
  666. if defined pb.cr (
  667.     if not "%~1"=="" (
  668.         setlocal enabledelayedexpansion
  669.         set "pb.back="
  670.         for /l %%p in (1 1 %pb.console.columns%) do set "pb.back=!pb.back! "
  671.         <nul set /p "pb.prompt=!pb.cr!!pb.back:~1!!pb.cr!"
  672.         endlocal
  673.     )
  674. )
  675. for /f "tokens=1 delims==" %%v in ('set pb.') do set "%%v="
  676. EXIT /B 0
  677.  
  678.  
  679.  
  680. REM https://stackoverflow.com/questions/20943733/in-batch-can-i-make-a-line-of-displayed-text-not-split-words-appart-when-it-goes#20944604
  681. :echoWrap [text]
  682.    rem Get the window width
  683.     set "width="
  684.     for /f "tokens=2 skip=4" %%f in ('mode con') do if not defined width set /a "width=%%f-1"
  685.     set "output="
  686.    rem For each word in input line
  687.     for %%b in (%*) do (
  688.        rem Add the new word
  689.         set "newOutput=!output! %%b"
  690.         if "!output!" equ "" set newOutput=!newOutput: =!
  691.        rem If new word don't exceed window width
  692.         if "!newOutput:~%width%,1!" equ "" (
  693.            rem Keep it
  694.             set "output=!newOutput!"
  695.         ) else (
  696.            rem Show the output before the new word
  697.             echo !output!
  698.            rem and store the new word
  699.             set "output=%%b"
  700.         )
  701.     )
  702.    rem Show the last output, if any
  703.     if defined output echo !output!
  704. EXIT /B 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top