[英]Windows command to search directory for a specific name, then move its files to parent
我一直在尝试使命令起作用:
for /r /d %d in (*) do if /I "%~nxd"=="_Success" for /f %f in (%d\*) do if exist %f move %f ..
我打算命令执行以下操作:
我一直在使用help
和以下主题来帮助我入门:
如何使用CMD将所有具有特定扩展名的文件从所有子目录移动到其父目录?
但是我在输出中又遇到了一些错误:
C:\migration_files\vault>if /I "document" == "_Success" for /F %f in (C:\migration_files\vault\document\*) do if exist %f move %f ..
...
C:\migration_files\vault>if /I "_Success" == "_Success" for /F %f in (C:\migration_files\vault\faqs\_Success\*) do if exist %f move %f ..
The system cannot find the file C:\migration_files\vault\faqs\_Success\*.
C:\migration_files\vault>if /I "_Success" == "_Success" for /F %f in (C:\migration_files\vault\patch\_Success\*) do if exist %f move %f ..
The system cannot find the file C:\migration_files\vault\patch\_Success\*.
编辑-似乎大部分工作,除了文件被移动到工作目录。
感谢@mihai_mandis在此链接中提供的解决方案:
我对它进行了以下修改:
@echo off
setlocal enabledelayedexpansion
for /r /d %%d in (*) do (
if /I "%%~nxd"=="_Success" (
for /f %%f in ("%%d\*") do (
call :GETPARENTPARENT "%%f" ret
echo ret=!ret!
move /Y "%%f" "!ret!"
)
)
)
goto:EOF
:GETPARENTPARENT
set fileP=%1
echo received=%fileP%
for %%a in (%fileP%) do (
set parent=%%~dpa
cd !parent!\..
set PPPath=!cd!
for %%x in ("!PPPath!") do (
set "%~2=%%~dpnx"
)
)
GOTO:EOF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.