用于遍历以特定字符串开头的目录的批处理脚本
Batch script to iterate through directories starting with a specific string
我目前必须手动编辑批处理文件以手动告诉它在哪个目录上工作。
它必须抓取的目录总是以“2020-”开头(至少今年是这样),如果我错过一天,有时会有多个目录。
(如果更简单的话,它们将始终采用这种格式:“0000-00-00”)
有没有办法编辑它来解决这个问题?
我试过将 source_directory 设为“2020*”,但我知道这可能不是这样的,哈哈,任何正确方向的帮助或指示都会很棒。
@echo off
pushd %~dp0
SET source_directory=2020-05-03
SET target_directory=%~dp0
for /f %%a IN ('dir "%source_directory%" /b') do (
move %source_directory%\%%a %target_directory%
)
抱歉,我不太经常使用 SO,所以我忘记了需要做的事情。
这是我想出的解决方案。我不认为这是执行此操作的直观方法,但我对批处理的理解不够深入,无法在没有嵌套循环的情况下执行此操作。
@echo off
pushd %~dp0
SET source_directory=????-??-??
SET target_directory=%~dp0
for /d %%s in (%source_directory%) do (
for /f %%a IN ('dir "%%s" /b') do (
move %%s\%%a %target_directory%
)
)
我目前必须手动编辑批处理文件以手动告诉它在哪个目录上工作。
它必须抓取的目录总是以“2020-”开头(至少今年是这样),如果我错过一天,有时会有多个目录。
(如果更简单的话,它们将始终采用这种格式:“0000-00-00”)
有没有办法编辑它来解决这个问题?
我试过将 source_directory 设为“2020*”,但我知道这可能不是这样的,哈哈,任何正确方向的帮助或指示都会很棒。
@echo off
pushd %~dp0
SET source_directory=2020-05-03
SET target_directory=%~dp0
for /f %%a IN ('dir "%source_directory%" /b') do (
move %source_directory%\%%a %target_directory%
)
抱歉,我不太经常使用 SO,所以我忘记了需要做的事情。
这是我想出的解决方案。我不认为这是执行此操作的直观方法,但我对批处理的理解不够深入,无法在没有嵌套循环的情况下执行此操作。
@echo off
pushd %~dp0
SET source_directory=????-??-??
SET target_directory=%~dp0
for /d %%s in (%source_directory%) do (
for /f %%a IN ('dir "%%s" /b') do (
move %%s\%%a %target_directory%
)
)