gpt4 book ai didi

sorting - Windows cmd 按文件类型对文件进行排序并将它们存储在文件夹中

转载 作者:行者123 更新时间:2023-12-02 04:41:26 26 4
gpt4 key购买 nike

我想要一个批处理文件,它将按文件类型对文件进行排序并将它们分类到文件夹中。例如,我将在某个文件夹中运行此批处理文件,.PDF 文件将保存在“PDF”文件夹中,其他文件类型也是如此。可以在命令行中做到这一点吗?谢谢。

最佳答案

请将下面的代码放在一个.bat文件中,然后将其保存到你的文件夹中并运行它。

@echo off
rem For each file in your folder
for %%a in (".\*") do (
rem check if the file has an extension and if it is not our script
if "%%~xa" NEQ "" if "%%~dpnxa" NEQ "%~dpnx0" (
rem check if extension forlder exists, if not it is created
if not exist "%%~xa" mkdir "%%~xa"
rem Copy (or change to move) the file to directory
copy "%%a" "%%~dpa%%~xa\"
)
)

关于sorting - Windows cmd 按文件类型对文件进行排序并将它们存储在文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20745044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com