[英]Windows batch file to move files from specific subfolders to another folder
I am a php developer and I know nothing about windows batch files. 我是php开发人员,对Windows批处理文件一无所知。 Maybe somebody will help me... 也许有人会帮我...
I have a directory structure like here: 我有一个像这样的目录结构:
directory1/1/ directory1/2/ directory1/5/ directory2/1/ directory2/2/ directory2/5/ etc...
How can I write a bat file that will do the following: -move all files from all sub-directories '1' into a different directory 我该如何写一个bat文件来执行以下操作:-将所有文件从所有子目录“ 1”移动到另一个目录中
I had tried this 我试过了
pushd %CD%\in\
for /r %%a in (*.*) do (
echo COPY "%%a" "%CD%\out\%%~nxa"
)
popd
but this code takes all the files from "in" folder and copies them to "out" folder. 但是此代码从“入”文件夹中获取所有文件,并将它们复制到“出”文件夹中。 How can I determine subdirectories here? 我如何在这里确定子目录?
You can do it with this batch command: 您可以使用以下批处理命令执行此操作:
@echo off
::Set Directory
set Dir=%CD%\in
::Set Destination
set Des=%CD%\out
::Set Sub Directory you want to move
set SubDir=1
if exist "%Dir%\*" (
if not exist "%Des%\*" mkdir "%Des%"
for /D %%a in ("%Dir%\*.*") do (
for /D %%b in ("%%a\*.*") do (
if "%%~nxb" EQU "%SubDir%" ROBOCOPY "%%b" "%Des%\%%~nxa\%%~nxb" /E /IS /MOVE>Nul
)
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.