![](/img/trans.png)
[英]Batch file to copy contents from sub-folder to parent only if there's one file and it's the same name without extension
[英]How to delete a specific sub-folder in a parent folder using a batch file?
我想創建一個批處理文件,刪除或刪除文件夾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
它將以遞歸方式刪除文件和文件夾,請謹慎,恕不提示。 它可以替代舊式的treetree。 最好。
編輯:在您的記事本中,創建具有以下內容的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
( md是make dir dos命令,因此所有以它開頭的行都在創建文件夾-最后一行是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%
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.