Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理文件,将单个子目录从多个父目录递归移动到另一个定义的单个目录_Batch File_Windows 7_Move_File Processing - Fatal编程技术网

Batch file 批处理文件,将单个子目录从多个父目录递归移动到另一个定义的单个目录

Batch file 批处理文件,将单个子目录从多个父目录递归移动到另一个定义的单个目录,batch-file,windows-7,move,file-processing,Batch File,Windows 7,Move,File Processing,如果这个标题还不够混乱的话。。希望我想做的事情更容易理解 Windows7只是为了以防万一 我在我工作的文件夹中有多个目录 C:\WorkingDir\1 C:\WorkingDir\2 C:\WorkingDir\3 and so on 每个文件夹(1、2、3等)中都有一个子目录,没有其他文件或文件夹 C:\WorkingDir\1\5E04AB C:\WorkingDir\2\4F07FC C:\WorkingDir\3\9DA04F 我需要将这些单独的子目录从父文件夹中移动到一个新文件

如果这个标题还不够混乱的话。。希望我想做的事情更容易理解

Windows7只是为了以防万一

我在我工作的文件夹中有多个目录

C:\WorkingDir\1
C:\WorkingDir\2
C:\WorkingDir\3
and so on
每个文件夹(1、2、3等)中都有一个子目录,没有其他文件或文件夹

C:\WorkingDir\1\5E04AB
C:\WorkingDir\2\4F07FC
C:\WorkingDir\3\9DA04F
我需要将这些单独的子目录从父文件夹中移动到一个新文件夹中

C:\NewFolder\5E04AB
C:\NewFolder\4F07FC
C:\NewFolder\9DA04F
就这样!我认为这可能很简单,但我不能对变量或更好的解释如何使用它们的资源了如指掌。我根本不怎么使用批处理文件,所以我非常抱歉这次求救。希望更有知识的人能给我一个简单的解释:-)

我发现:

但是,有人能把我链接到一个资源,在那里我可以了解更多关于批处理变量和参数的信息,以供将来参考吗

谢谢谢谢谢谢

更新:

@恩多 谢谢你的回复。在我第一次尝试运行您的代码时,一定有用户错误。它工作正常,一切正常!非常感谢你

更新2 在运行代码User1之后,它将创建我的NewFolder目录,但不会向其中复制任何内容。它仍然是空的。以下是我在DOS中运行时的一些重复输出:

C:\WorkingDir>(
set fldr2=C:\WorkingDir\1\5E04AB
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.

C:\WorkingDir>(
set fldr2=C:\WorkingDir\2\4F07FC
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.

C:\WorkingDir>(
set fldr2=C:\WorkingDir\3\9DA04F
 move "C:\WorkingDir\\" "C:\NewFolder\"
)
The system cannot find the file specified.`

请查看输出并删除回声,如果正常:

@echo off &setlocal 
set "workingdir=WorkingDir"
md "C:\NewFolder" 2>nul

pushd "%workingdir%"
cd
for /d %%i in (*) do for /d %%j in ("%%~i\*") do echo move "%%~fj" "C:\NewFolder\%%~nxj"
popd

我无法对此进行测试,但:

@echo off
setlocal EnableDelayedExpansion
md "c:\NewFolder\"
cd "C:\WorkingDir\"
for /D /r %%a in ("*") do (
    set fld1=%%a
    cd "%fld1%"
    for /D /r %%b in ("*") do (
        set fld2=%%b
        move "c:\WorkingDir\%fld1%\%fld2%" "C:\NewFolder\%fld2%"
        )
    )
这是一个很好的批处理资源:


好的,我试过了,但每次运行时都只能得到“命令的语法不正确”
@echo off
设置“workingdir=C:\workingdir”
nul
pushd”%workingdir%%“
for/d%%i in(*)do for/d%%j in(%%~i\*”)do echo move“%%~fj”“C:\NewFolder\%%~nxj”
popd
您是要修复这组特定文件夹,还是要解决一般问题?我不知道如何让我的评论在回复时以适当的间隔显示所有内容。。我在代码中使用了反勾号,但它没有正确显示间距和换行符。也没用..我检查了代码,这里没问题。您是否看到
cd
命令的输出?这应该显示
C:\WorkingDir
。对我也适用-我直接复制了OP的版本。唯一的变化是我用的驱动器号。啊!我不知道我第一次做了什么,但是是的,它工作得非常完美。非常感谢。它运行但不工作。我将在一秒钟内编辑我的原始问题,以显示此批处理脚本的输出。感谢您提供有关批处理信息的链接@user2291844:您介意测试这个版本并告诉我它是如何运行的吗?