且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

批量脚本创建基于文件名的文件夹

更新时间:2022-10-23 16:29:28

从命令行

  for / f%f in('dir * .png / b')做md%〜nf&移动%f .\%〜nf\0000.png 

如果在批处理文件中

  for / f %% f in('dir * .png / b')do md %%〜nf&移动%f .\ %%〜nf\0000.png 

p>

  c:\Temp\pp> dir / s / b 
c:\Temp\pp\b .png
c:\Temp\pp\p.png

c:\Temp\pp> for / f%f in('dir * .png / b')做md%〜nf&移动%f .\%〜nf\0000.png

c:\Temp\pp> md b&移动b.png .\b\0000.png
1个文件被移动。

c:\Temp\pp> md p&移动p.png .\p\0000.png
1个文件被移动。

c:\Temp\pp> dir / s / b
c:\Temp\pp\b
c:\Temp\pp\p
c:\Temp\pp\b\0000.png
c:\Temp\pp\p\0000.png


I have a folder with a lot of PNG images that I want to create folders for based on their filenames. I would then want the files to be moved into their respective folders of the same name and renamed to 0000.png.

Example:

- abcd.png
- efghi.png
- jklm.png
- nopqr.png
- stuv.png
- wxyz.png

To:

- abcd/0000.png
- efghi/0000.png
- jklm/0000.png
- nopqr/0000.png
- stuv/0000.png
- wxyz/0000.png

from the command line

for /f %f in ('dir *.png /b') do md %~nf & move %f .\%~nf\0000.png

if in the batch file

for /f %%f in ('dir *.png /b') do md %%~nf & move %f .\%%~nf\0000.png

Here is the example

c:\Temp\pp>dir /s/b
c:\Temp\pp\b.png
c:\Temp\pp\p.png

c:\Temp\pp>for /f %f in ('dir *.png /b') do md %~nf & move %f .\%~nf\0000.png

c:\Temp\pp>md b   & move b.png .\b\0000.png
        1 file(s) moved.

c:\Temp\pp>md p   & move p.png .\p\0000.png
        1 file(s) moved.

c:\Temp\pp>dir /s/b
c:\Temp\pp\b
c:\Temp\pp\p
c:\Temp\pp\b\0000.png
c:\Temp\pp\p\0000.png