Automatically classify folders by file name (windows Bash)

 

REM List file names, sorted by file name---------

dir /b /on > list.txt

REM Find JPG files

findstr ".JPG" list.txt > target.txt

rem delete file extension-------------------------

@echo off & setlocal enabledelayedexpansion

rem reads all the contents of target.txt

for /f "eol=* tokens=*" %%i in (target.txt) do (

rem sets variable a to the content of each line

set a=%%i

rem If the line has .JPG, change it to

set "a=!a:.JPG=!"

rem saves all modified lines into $

echo !a!>>$)

rem replaces the original a.txt content with the content of $

move $ target.txt

REM Create folder-----------------------------

rem reads all the contents of target.txt

for /f "eol=* tokens=*" %%i in (target.txt) do (

set string=%%i

echo "%%i"

for /f "tokens=1,2 delims=_" %%a in ("%%i") do (

set BEFORE_UNDERSCORE=%%a

set AFTER_UNDERSCORE=%%b

echo %%a

md %%a

rem Move files to folder

move %%i*.* %%a

))

del list.txt

del target.txt

留言

這個網誌中的熱門文章

error message : configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%)']/following::android.widget.EditText"

OSError: [Errno 22] Invalid argument: