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
In general analysis, the last sentence is the key point: When reading the configuration file config.ini, there are % caused by Solution one: Most likely configparser is reading the literal "%" sign in the string. The '%' symbol is used for string interpolation (substitution). If you want to use a literal "%", you can escape it with another "%". For example, use "100%%" to mean "100%" in configuration variables read by configparser. Solution two: Change from cf= configparser.ConfigParser() to : cf = configparser.RawConfigParser()
留言