我可以在我的批处理文件中使用 robocopy 的替代方法,我可以在路径中使用通配符吗?

Is there an alternative to robocopy I can use in my batch file where I can use a wildcard in the path?

我已经完成搜索并知道我不能在带有 robocopy 的路径中使用通配符

我只需要一个目录中的 .csv 文件,但还有很多目录包含我不想要的 .csv 文件,所有这些目录都具有不同的父目录。

例如:

@echo off

set X="1"

set "source=\Location\To\My\Documents\*\EXPORT\FILE"

set "destination=C:\Users\Public\Documents\Production"

robocopy "%source%" "%destination%" .csv /minage:%X%

exit /b

您可以使用 for /D loop for resolving the wildcard *:

@echo off
set "X=1" & rem // (regard the corrected quotation herein!)
set "source_main=\Location\To\My\Documents"
set "source_sub=EXPORT\FILE"
set "destination=%PUBLIC%\Documents\Production"
set "file_mask=*.csv"

rem // Change into source main directory and resolve UNC path:
pushd "%source%" && (
    rem // Let the following loop resolve any wildcards:
    for /D %%I in ("*") do (
        rem // The following command is executed for every matching sub-directory:
        robocopy "%%~I\%source_sub%" "%destination%" "%file_mask%" /minage:%X%
    )
    rem // Return from source main directory:
    popd
)
exit /B