gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 21:39:10 27 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/

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