DePhoegon icon

[Framework] Javascript Array list builder

DePhoegon | PRO | 01/17/19 02:13:45 AM UTC | 0 ⭐ | 590 👁️ | Never ⏰ | []
Batch |

3.08 KB

|

None

|

0 👍

/

0 👎

 @echo off
:: setting empty variables for use.
 set n1=
 set name=
 set rname=
 set namectl=
:: Creating Text file, for pasting into array
 echo [ > list.txt
:: Creates Text file, for tracking which files get renamed. Currently removes 'Spaces' & ' - ' 
 echo renamed files > Rlist.txt
:: Loops can be extended easily to include any file time
:: ~nx is 'name' & 'extension' for the vairable.  without, the full variable would be 'c:\examplefolder\Examplename.jpg', and with it is 'Examplename.jpg'
 for  %%t in (*.jpg) do call :Deepend %%~nxt
 for  %%k in (*.png) do call :Deepend %%~nxk
:: End of list
 echo ]>> list.txt
 goto :eof
:: Prime & reseting of key variables between loops
 :Deepend
 set n1=/
 set tep=%1^/
 set name=%1
 set namectl=n
 :loop
:: Testing for 'problem' characters in a subloop setup and either inserting a special character or editing it out
 if "%tep:~0,1%"==" " goto :edit
 if ^%tep:~0,1%==^/ goto :Last
 :: unneeded when escape characters arent needed. -if ^%tep:~0,1%==^. goto :Check
 if ^%tep:~0,1%==^- goto :edit
 if not %n1%==/ set n1=%n1%%tep:~0,1%
 if %n1%==/ set n1=%tep:~0,1%
 goto :chop
 :Check
:: Inserts escape character, for problematic characters that can not be removed
 if not %n1%==/ set n1=^%n1%^\^%tep:~0,1%
 if %n1%==/ set n1=^\^%tep:~0,1%
 goto :chop
 :edit
::sets a rename flag, then edits the problem bit out of the listed name, providing feedback on in progress names to show working status
 set namectl=y
 set tep=%tep:~1%
 echo processing File Name
 echo %n1%~~
 goto :loop
 :Last
:: lasts step, puts the file into the list.txt & jumps to renaming file on the folder to remove problematic characters
:: use of %n1% should be wrapped in the proper formatting and including folders to pictures with the correct slash
 echo %n1%>> list.txt
 if %namectl%==y goto :rename
 exit /b
 :rename
:: sets/resets key renaming variables
 set tname=%n1%*
 set rname=
 :Renamestart
::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'
:: if found skips to renaming action
 if %tname%==* goto :renamed
::Subloops checking for problematic characters
 if "%tname:~0,1%"==" " goto :renames
 if ^%tname:~0,1%==^\ goto :renames
:: skips if problem characters, builds temp variable for new name
 if not %rname%.==. set rname=^%rname%^%tname:~0,1%
 if %rname%.==. set rname=^%tname:~0,1%
 :renames
:: sets the cuts the used character out of the temporary variable, then restarts subloop
 set tname=%tname:~1%
 goto :Renamestart
 :renamed
::renames file [windows specific] & exits the forloop to the next file
 rename %name% %rname%
 echo renamed %name% to %rname% >> Rlist.txt
 exit /b
 :chop
::chops the used character out of the variable & restarts the subloop
 set tep=%tep:~1%
 echo processing File Name
 echo %n1%~~
 goto :loop
 :End

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎