简体   繁体   English

Windows批处理文件,用于将文件从特定的子文件夹移动到另一个文件夹

[英]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.

相关问题 如何将特定文件从多个子文件夹移动到各自的父文件夹? (Windows批处理) - How can I move specific files from multiple subfolders to their respective parent folder? (Windows batch) windows 批处理文件脚本,用于从文件夹中选择随机文件并将它们移动到另一个文件夹 - windows batch file script to pick random files from a folder and move them to another folder 使用 Windows 批处理脚本将多个文件从子文件夹移动到单个文件夹 - Move Multiple Files from Subfolders to Single Folder using Windows batch script 批处理文件,用于在特定时间间隔内将.txt文件从一个文件夹移动到另一个文件夹,从而检查大小 - Batch file to move .txt files from one folder to another in a specific time interval keeping a check on the size Windows批处理将文件从子文件夹复制到一个文件夹 - Windows batch copy files from subfolders to one folder Windows 批处理文件 xcopy 同一文件夹中的特定文件 - Windows Batch File xcopy specific files from same folder Windows批处理以覆盖文件夹和子文件夹中的现有文件 - Windows Batch to Overwrite Existing files in folder and subfolders 使用批处理或VBS将文件夹和子文件夹移动到另一个文件夹 - Move a Folder and Subfolders to another Folder using Batch or VBS 批处理脚本,将文本从特定文件追加到子文件夹中的所有文件 - batch script to append text from specific file to all files in subfolders 批处理文件可将一个文件夹中的文件和文件夹移动到另一个文件夹 - Batch file to move files and folders in a folder to another folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM