AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 42856
Accepted
Simon Johnson
Simon Johnson
Asked: 2009-07-21 00:05:08 +0800 CST2009-07-21 00:05:08 +0800 CST 2009-07-21 00:05:08 +0800 CST

只删除 ASP 文件

  • 772

我正在尝试编写一个仅删除.asp 文件的 Windows 批处理脚本文件。

如果我做:

del *.asp /s

这具有删除任何扩展名为 .aspx 的文件的副作用。这很糟糕,因为我想保留带有 aspx 扩展名的文件。

这个问题有没有不需要安装自定义应用程序的解决方案?

windows batch-file
  • 3 3 个回答
  • 188 Views

3 个回答

  • Voted
  1. Best Answer
    Dennis Williamson
    2009-07-21T01:11:21+08:002009-07-21T01:11:21+08:00

    这似乎在 Vista 上起到了作用:

    for %i in (*.asp) do @if not %~xi==.aspx del %i
    

    了解更多信息

    help for
    

    变量有各种修饰符:

    此外,增强了 FOR 变量引用的替换。您现在可以使用以下可选语法:

    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string
    
    • 4
  2. James F
    2009-07-21T00:33:19+08:002009-07-21T00:33:19+08:00

    我怀疑因为 del 是一个 DOS-vintage 命令,它不理解超过 3 个字符的扩展名。

    我可以看到几种解决方案,其中只有一种您会喜欢,而没有一种适合您的确切要求:

    • 手动运行并添加 /p 开关以提示和跳过 aspx 文件
    • 安装powershell(假设您使用的是 XP 或更新版本),它应该有一种方法可以以更细粒度的方式遍历文件。我不是 powershell 专家,但这可能是最好的选择,因为它至少是一个 Windows 组件而不是自定义应用程序
    • 安装 GNU findutils和coreutils并像在 unix 上那样删除文件:“find directoryname -name '*.asp' | xargs rm”。好处:它会起作用。缺点:它绝对是定制的
    • 如果你已经在盒子上安装了 Perl 或 C 或 Java 来做一些与你在 powershell 中做的事情相同的事情
    • 1
  3. Richard
    2009-07-21T01:57:35+08:002009-07-21T01:57:35+08:00

    Powershell 将执行此操作。虽然dir -r *.asp将 match *.aspx,但您可以轻松地优化输出:

    dir . -r -inc *.asp
    

    用于匹配PSH-include中的通配符,而不是-filter(通常更快)与 Win32 API 匹配(结果与 相同cmd.exe)。

    您可能只想删除文件,因此,为了测试:

    dir . -r -inc *.asp | ?{-not $_.PSIsContainer} | del -whatif
    

    用于-whatif仅列出会发生的情况。用于-confirm提示配置文件删除。用于避免使用别名的脚本,但会列出已完成的操作:

    Get-ChildItem -path . -recurse -include *.asp | 
      Where-Object {-not $_.PSIsContainer} |
      Remove-Item -Verbose
    
    • 0

相关问题

  • 您最喜欢的云计算提供商是什么?[关闭]

  • Vanilla Powershell 是否足以成为 Windows 和 DB 服务器管理员的语言?

  • 为什么添加新驱动器后我的磁盘驱动器访问速度如此之慢?

  • 在 Windows Server 2003 下使用 wscipt 从 .asp 文件运行 .exe

  • 最佳混合环境(OS X + Windows)备份?[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve