【问题标题】:Remove a file from folder using changeable path folder使用可变路径文件夹从文件夹中删除文件
【发布时间】:2020-01-13 17:32:31
【问题描述】:

我想删除同一工作区文件夹中许多项目中存在的文件夹,如下所示:

工作区:
/project1/生成
/project2/生成

我尝试了下面的代码,但无法正常工作:

del /q "workspace\(*)\generated\*"
FOR /D %%p IN ("workspace\(*)\generated\*.*") DO rmdir "%%p" /s /q

请有人帮忙吗? 提前致谢。

【问题讨论】:

  • 您需要说明您是尝试删除 generated 目录,还是empty 他们。

标签: batch-file cmd command


【解决方案1】:

如果您要删除目录(及其包含的所有文件),则以下操作将起作用。当您确信将删除正确的目录时,请从 Remove-Item 命令中删除 -WhatIf

Get-ChildItem -Directory -Path 'C:\workspace\project*\generated' | Remove-Item -Recurse -WhatIf

如果您必须从 cmd.exe shell 或 .bat 脚本执行此操作,您可以:

powershell -NoLogo -NoProfile -Command ^
    "Get-ChildItem -Directory -Path 'C:\workspace\project*\generated' | " ^
        "Remove-Item -Recurse -WhatIf"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 2022-01-12
    • 2014-12-11
    相关资源
    最近更新 更多