Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Windows 如何使用批处理文件删除父文件夹中的特定子文件夹?_Windows_Batch File_Cmd - Fatal编程技术网

Windows 如何使用批处理文件删除父文件夹中的特定子文件夹?

Windows 如何使用批处理文件删除父文件夹中的特定子文件夹?,windows,batch-file,cmd,Windows,Batch File,Cmd,我想创建一个批处理文件,删除或删除文件夹C:\temp\root\students\type1、其子文件夹和所有文件 我的文件夹和文件如下: C:\temp C:\temp\root C:\temp\root\students C:\temp\root\tutors C:\temp\root\students\type1 C:\temp\root\students\type2 C:\temp\root\tutors\type1 C:\temp\root\tutors\type2 C:\temp\

我想创建一个批处理文件,删除或删除文件夹
C:\temp\root\students\type1
、其子文件夹和所有文件

我的文件夹和文件如下:

C:\temp
C:\temp\root
C:\temp\root\students
C:\temp\root\tutors
C:\temp\root\students\type1
C:\temp\root\students\type2
C:\temp\root\tutors\type1
C:\temp\root\tutors\type2
C:\temp\root\students\type1\details.txt
C:\temp\root\students\type1\assignment1
C:\temp\root\students\type1\assignment1\results.txt
批处理文件中指定了文件夹
C:\temp\root\students\type1\assignment1

我想向上移动一个文件夹/目录,删除或删除批处理文件(test.bat)中的
C:\temp\root\students\type1

请帮我做这个。

使用这个:

rd /s /q C:\temp\root\students\type1
它将递归删除文件和文件夹,注意,无需提示。它有点像是一棵好树的替代品。最好的

编辑:在记事本中,使用以下内容创建您的mygoodbatch.bat

md C:\temp
md C:\temp\root
md C:\temp\root\students
md C:\temp\root\tutors
md C:\temp\root\students\type1
md C:\temp\root\students\type2
md C:\temp\root\tutors\type1
md C:\temp\root\tutors\type2
md C:\temp\root\students\type1\details.txt
md C:\temp\root\students\type1\assignment1
md C:\temp\root\students\type1\assignment1\results.txt
rd /s /q C:\temp\root\students\type1
mdmake dirdos命令,因此所有以它开头的行都在创建文件夹-最后一行是删除级别4AA的行)


将此批处理保存在磁盘的根目录下,然后运行它。我真希望这就是你想要的。我还不明白的是:您正在创建一个目录结构,同时,排除了级别4AA。。。是吗?

您可以使用for循环获取给定文件夹的父文件夹:

set target_dir=C:\temp\root\students\type1.test\assignment1

for %%a in ("%target_dir%") do (
    echo Removing %%~dpa%
    rd /s/q %%~dpa%
)

C是一种编程语言,而不是你的东西所在的硬盘。这不应标记为C。现有的批处理文件命令在哪里?只需更改文件夹以满足您的需要非常感谢您的回复。这些是物理文件夹/目录。有没有办法从批处理文件中检索此文件夹结构并删除此特定文件夹?我所说的文件夹结构是:C:\temp是一级C:\temp\root是二级C:\temp\root\students是三级C:\temp\root\tutors是三级C:\temp\root\students\type1是四级AA C:\temp\root\students\type2是四级AB C:\temp\root\tutors\type1是四级BA C:\temp\root\tutors\type2是四级BBsorry,不确定我是否理解正确。主要原则是:从我上面的回答中,您放置在C:\temp\root\students\type1位置的任何内容都将被删除。在我的批处理文件中,我希望按照下面提到的级别创建此文件夹结构,并删除引用级别4AA的文件夹。我是新手,所以我的批处理文件中还没有任何内容。谢谢你的时间和帮助。我弄糊涂了。直到现在,您还没有提到创建文件夹,只是排除了…:希望我能帮上忙。