将文件移动到与部分名称的文件夹(Move files to folders with partial

2019-09-29 16:59发布

我有大约250个文件,我需要移动到特定的文件夹。 问题是,文件夹只有文件的部分名称。

例如,我需要移动文件“12345.txt”文件夹“12345 - 你好”,因为每个文件夹中的实际文件名开始。

我可以在DOS批处理文件中做到这一点?

谢谢。

Answer 1:

假设Windows中,它实际上并不难:

@echo off
rem loop over all files
for %%f in (*) do call :process "%%f"

rem this is necessary to avoid running the subroutine below
rem after the loop above ended
goto :eof

rem subroutine that gets called for every file
rem this finds the first matching folder and moves the file there
:process
rem the /d loops over all directories - the mask ensures that
rem the directory name starts with the given file name (without
rem extension)
for /d %%d in ("%~n1*") do (
    echo Moving "%~1" to "%%d" ...
    move "%~1" "%%d"
    rem Return since the file was moved already
    goto :EOF
)

也可以在发现我的SVN仓库 。



文章来源: Move files to folders with partial names