【问题标题】:Locate and Delete Folder(s) with Command Prompt使用命令提示符查找和删除文件夹
【发布时间】:2013-04-19 12:59:14
【问题描述】:

在工作中,我们每天都会处理需要帮助以在家中登录网上银行的人。有时我们需要用户删除文件并指导他们执行此操作,这在很多时候可能会让人感到厌烦和麻烦,因为用户对计算机缺乏经验,因此浪费了多达 20 分钟。

我们一直在讨论一种解决方案(如果可能),让用户下载我们告诉他们运行的批处理文件,然后可以为我们删除所需的文件。我在这里问这个问题,因为我们在这里工作的人都没有批处理文件的经验。

就我个人而言,我经常使用它,但我无法真正想出适合我们需求的解决方案,当我在网上搜索时,我也找不到适合的解决方案。脚本必须自动定位文件夹(如果可能)。

  1. 这可能吗?
  2. 您能帮我完成这项工作吗?

提前致谢!

【问题讨论】:

  • 您实际上是是指 DOS,还是Windows 中的命令提示符?虽然相似,但它们是一回事。
  • 我不完全了解您的意思,但我想说您的任务可以使用批处理文件完成。尝试将您尝试执行的任务拆分为多个部分(例如 1. 搜索文件夹 2. 要求删除 3. 删除文件夹)并在网络上仅搜索这些部分;)
  • 如何识别文件?这些文件有什么共同特点?
  • @Damien_The_Unbeliever 你说得对。我会更正它,因为它是命令提示符。
  • @user2033427 应该只是文件夹。每次都有相同的名字。

标签: batch-file command-prompt


【解决方案1】:

一个简单的:

rd /s "%USERPROFILE%\.oces2"

如果他们遵循某种模式(例如,以 .oces 开头):

@echo off
cd /d "%USERPROFILE%"
for /d %%i in (.oces*) do rd /s "%%i"
pause

【讨论】:

  • 文件夹名称是否遵循某种模式(例如,它们以 .oces 开头)?
【解决方案2】:

也许这可以帮助你,我评论了它以便你了解它在做什么;)

:: Program to remove Folders which fullfill the criterias

:: You won't see the commands in the console
@echo off

:: Go to drive C (i think you'll need application data or similar and this is 
:: on c, but if the bat is started in an other partition, it will search the 
:: one he starts in
C:
:: Go to the path in which you'll search, if you want C:\ , remove this
CD "C:\yoursearchstartpath"

:: Okay, this is the loop, it gets all folders ( /A -D  is for folders)
:: which have delMe in their name and then asks if you want to delete it
:: showing the path to make sure you don't delete sth accidentially
for /f "delims=" %%a IN ('dir /S /B /A -D *delMe*') do RD /S "%%a"

:: That the batch file is not closed automatically but shows that it's finished
set /p id="Finished, press Space to quit " %=%

【讨论】:

    【解决方案3】:

    查看此链接

    http://support.microsoft.com/kb/65994

    我创建了一个示例批处理文件 A.BAT。它检查 C:\Folder\F1 是否存在,如果可用则删除文件夹 F1

    IF EXIST D:\FOLDER\F1 GOTO A
    EXIT
    :A
    D:
    DEL D:\FOLDER\F1\*.*
    RMDIR F1
    

    希望对你有帮助

    【讨论】:

    • 添加了 DEL . 命令以清除文件夹,然后使用 RMDIR 删除文件夹
    猜你喜欢
    • 2011-12-11
    • 2012-02-28
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2021-04-11
    相关资源
    最近更新 更多