Advertisement
DePhoegon

[Framework] Javascript Array list builder

Jan 16th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.08 KB | None | 0 0
  1.  @echo off
  2. :: setting empty variables for use.
  3.  set n1=
  4.  set name=
  5.  set rname=
  6.  set namectl=
  7. :: Creating Text file, for pasting into array
  8.  echo [ > list.txt
  9. :: Creates Text file, for tracking which files get renamed. Currently removes 'Spaces' & ' - '
  10.  echo renamed files > Rlist.txt
  11. :: Loops can be extended easily to include any file time
  12. :: ~nx is 'name' & 'extension' for the vairable.  without, the full variable would be 'c:\examplefolder\Examplename.jpg', and with it is 'Examplename.jpg'
  13.  for  %%t in (*.jpg) do call :Deepend %%~nxt
  14.  for  %%k in (*.png) do call :Deepend %%~nxk
  15. :: End of list
  16.  echo ]>> list.txt
  17.  goto :eof
  18. :: Prime & reseting of key variables between loops
  19.  :Deepend
  20.  set n1=/
  21.  set tep=%1^/
  22.  set name=%1
  23.  set namectl=n
  24.  :loop
  25. :: Testing for 'problem' characters in a subloop setup and either inserting a special character or editing it out
  26.  if "%tep:~0,1%"==" " goto :edit
  27.  if ^%tep:~0,1%==^/ goto :Last
  28. :: unneeded when escape characters arent needed. -if ^%tep:~0,1%==^. goto :Check
  29.  if ^%tep:~0,1%==^- goto :edit
  30.  if not %n1%==/ set n1=%n1%%tep:~0,1%
  31.  if %n1%==/ set n1=%tep:~0,1%
  32.  goto :chop
  33.  :Check
  34. :: Inserts escape character, for problematic characters that can not be removed
  35.  if not %n1%==/ set n1=^%n1%^\^%tep:~0,1%
  36.  if %n1%==/ set n1=^\^%tep:~0,1%
  37.  goto :chop
  38.  :edit
  39. ::sets a rename flag, then edits the problem bit out of the listed name, providing feedback on in progress names to show working status
  40.  set namectl=y
  41.  set tep=%tep:~1%
  42.  echo processing File Name
  43.  echo %n1%~~
  44.  goto :loop
  45.  :Last
  46. :: lasts step, puts the file into the list.txt & jumps to renaming file on the folder to remove problematic characters
  47. :: use of %n1% should be wrapped in the proper formatting and including folders to pictures with the correct slash
  48.  echo %n1%>> list.txt
  49.  if %namectl%==y goto :rename
  50.  exit /b
  51.  :rename
  52. :: sets/resets key renaming variables
  53.  set tname=%n1%*
  54.  set rname=
  55.  :Renamestart
  56. ::Skips to renaming if special character, that is forbidden in file system names exist (can be changed, though suggested to use a forbidden character file system that doesn't cause issues in batch, for windows no regex is needed as forloop sets the exact name and * is forbidden from use, allowing detection of special character to mark the end of the 'string'
  57. :: if found skips to renaming action
  58.  if %tname%==* goto :renamed
  59. ::Subloops checking for problematic characters
  60.  if "%tname:~0,1%"==" " goto :renames
  61.  if ^%tname:~0,1%==^\ goto :renames
  62. :: skips if problem characters, builds temp variable for new name
  63.  if not %rname%.==. set rname=^%rname%^%tname:~0,1%
  64.  if %rname%.==. set rname=^%tname:~0,1%
  65.  :renames
  66. :: sets the cuts the used character out of the temporary variable, then restarts subloop
  67.  set tname=%tname:~1%
  68.  goto :Renamestart
  69.  :renamed
  70. ::renames file [windows specific] & exits the forloop to the next file
  71.  rename %name% %rname%
  72.  echo renamed %name% to %rname% >> Rlist.txt
  73.  exit /b
  74.  :chop
  75. ::chops the used character out of the variable & restarts the subloop
  76.  set tep=%tep:~1%
  77.  echo processing File Name
  78.  echo %n1%~~
  79.  goto :loop
  80.  :End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement