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
    • 最新
    • 标签
主页 / computer / 问题 / 1500545
Accepted
root
root
Asked: 2019-11-10 05:05:39 +0800 CST2019-11-10 05:05:39 +0800 CST 2019-11-10 05:05:39 +0800 CST

删除名称或路径中没有特殊字符 ® 的文件

  • 772

我已经看到如何删除名称中没有特定字符串的所有文件

但是,我想删除文件名或路径中没有特定字符串的文件(不仅是文件名),并且我希望该字符串是字符 ®。

根据此修订历史,以下内容适用于字符串“MS”,但不适用于特殊字符:

@echo off
setlocal disableDelayedExpansion
for /f "usebackq tokens=*" %%i in (`dir /a:-d /b /s *.zip ^| findstr /v MS` ) do (
  echo del /s /q %%i
)
endlocal
windows windows-7
  • 3 3 个回答
  • 701 Views

3 个回答

  • Voted
  1. Best Answer
    FastEthernet
    2019-11-10T05:16:05+08:002019-11-10T05:16:05+08:00
    # ®
    $specialChar = [char]0x00AE
    Get-ChildItem -File -Recurse | Where-Object {!$_.FullName.Contains($specialChar)} | Remove-Item
    

    对于不支持该-File参数的旧版本 PowerShell,请使用:

    Get-ChildItem -Recurse | Where-Object {!$_.FullName.Contains($specialChar) -and -not $_.PSIsContainer} | Remove-Item
    
    • 3
  2. Io-oI
    2019-11-10T13:54:25+08:002019-11-10T13:54:25+08:00


    •更新- 使用Powershell:


    Get-childitem -re . | Where-Object {$_ -NotMatch '(?:®)'}|remove-item -recurse -force -Confirm:$false
    
    # Or, by using alias #
    gci -re . | ? {$_ -NotMatch '(?:®)'}| rd -re -force -Confirm:$false
    


    • 还有,可以更短的cmd/bat:


    :: in command line :: 
    chcp 1252 >nul & for /f "tokens=*" %i in ('dir /a:-d /b /s *.zip ^|find /v "®"')do echo=del /q /f "%~fi"
    
    :: in cmd/bat file ::
    @echo off && >nul chcp 1252
    
    for /f "tokens=*" %%i in ('dir /a:-d /b /s *.zip ^|find /v "®"')do echo=del /q /f "%%~fi"
    
    • 我之前的答案可能会被使用,但也可以使用!:

    @echo off & >nul chcp 1252 
    
    for /f "tokens=*" %%i in ('dir /a:-d /b /s *.zip')do (
        echo/"%%~i"|find "®">nul||echo=del /q /f "%%~fi" )
    

    或在命令行中::

    >nul chcp 1252 && for /f "tokens=*" %i in ('dir /a:-d /b /s *.zip')do @echo="%~fi"|find "®">nul||@echo=del /q /f "%~fi"
    

    Obs.:要添加®您的代码,请尝试...

    • 按住 alt (左)+(数字键盘)1 6 9

    在此处输入图像描述


    也许这可以帮助?


    事实上,特殊的控制台字符,它激活页面并对其进行编码,用于写入/读取文件名,并将该信息移动到变量,在字母汤中读取和比较它,在 cmd/bat 中有点难以处理,这就是为什么我寻求语言帮助的原因......

    因此,对于一个偏执的提议,考虑到删除文件的操作,我使用 C# 尝试使用 base64 对字符串进行比较(通配符 alt 169 = ®)。


    • Obs.: 169 = ®和不同于0169 = ©

    这些操作的结果是一个脚本 cmd/bat,它在运行时将一个 C# 源代码编译成一个可执行文件,脚本将使用它从文件名中获取字符串,是否存在字符名(在 base64 中)在名字里。


    这是我的朋友,还是和上面曝光的完全不同的东西,而且,我的英语有限,无法向你解释清楚:)


    • script cmd/bat: _

    @echo off && setlocal EnableExtensions EnableDelayedExpansion & chcp 1252 1>nul
    
    cd /d "%~dp0" && set "_.net=%windir%\Microsoft.NET" && title >nul && title Q1500545 
    set "_arg=/t:exe /out:"%temp%\b64.exe" "%temp%\b64.cs" /platform:anycpu /unsafe+ /w:0 /o"
    set "_here=." type nul >"%temp%\b64.cs" && set "_b64=%temp%\b64.exe" && >"%temp%\b64.cs"^
       (
        echo/ using System^;namespace b64 ^{class Program ^{static void Main^(string[] args^)
        echo/ ^{if ^(args.Length ^> 1 ^&^& args[0] ^=^= "-e" ^| args[0] ^=^= "-E"^)
        echo/ ^{byte[] plainTextBytes ^= System.Text.Encoding.UTF8.GetBytes^(args[1]^)^;
        echo/ Console.Write^(System.Convert.ToBase64String^(plainTextBytes^)^)^;
        echo/ ^}else if ^(args.Length ^> 1 ^&^& args[0] ^=^= "-d" ^| args[0] ^=^= "-D"^)
        echo/ ^{byte[] base64EncodedBytes ^= System.Convert.FromBase64String^(args[1]^)^;
        echo/ Console.Write^(System.Text.Encoding.UTF8.GetString^(base64EncodedBytes^)^)^;
        echo/ ^}^}^}^} 
        ) 
    
    for /f delims^=^ eol^=* %%i in ('%__APPDIR__%where.exe /r "!_.net!" "csc.exe"^|findstr /li k\v2\.
    ')do "%%~i" !_arg! /nologo && cd /d "%~dp0" && goto :^?
    
    :^?
    for /f delims^=^ eol^=* %%i in ('%__APPDIR__%where.exe /r "." "*.zip"')do call :^[ %%~fi
    (for %%D in (exe,cs)do del /q "%temp%\b64.%%D") & endlocal && exit /b 
    
    :^[
    for /f tokens^=* %%a in ('"cmd /u /c echo=%~1|find /v """
    ')do "!_b64!" -e %%~a|findstr "wq4=" >nul && exit /b )
    echo/del /f /q "%~1" && exit /b 
    
    

    • 我用于测试的目录树G:\SUPER_USER\Q1500545:

    G:.
    ¦   Q1500545.cmd
    ¦
    +---Sub_Dir_01
    ¦       test_º.zip
    ¦       test_¿.zip
    ¦       test_®.zip
    ¦
    +---Sub_Dir_02
    ¦       test_®.zip
    ¦       test_º.zip
    ¦       test_¿.zip
    ¦
    +---Sub_Dir_03
    ¦       test_®.zip
    ¦       test_º.zip
    ¦       test_¿.zip
    ¦
    +---Sub_Dir_04_®
            test_®.zip
            test_º.zip
            test_¿.zip
    


    • 我的脚本echo/del /f /q "%~1"结果 :

    del /f /q "G:\SUPER_USER\Q1500545\Sub_Dir_01\test_º.zip"
    del /f /q "G:\SUPER_USER\Q1500545\Sub_Dir_01\test_¿.zip"
    del /f /q "G:\SUPER_USER\Q1500545\Sub_Dir_02\test_º.zip"
    del /f /q "G:\SUPER_USER\Q1500545\Sub_Dir_02\test_¿.zip"
    del /f /q "G:\SUPER_USER\Q1500545\Sub_Dir_03\test_º.zip"
    del /f /q "G:\SUPER_USER\Q1500545\Sub_Dir_03\test_¿.zip"
    


    • 我的C#代码:

    using System;
    namespace b64 
    
    {  
       class Program 
       {  
          static void Main(string[] args)
          {
             if (args.Length > 1 && args[0] == "-e" | args[0] == "-E")
             {  
                byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(args[1]);
                Console.Write(System.Convert.ToBase64String(plainTextBytes));
    
             }  
               else if (args.Length > 1 && args[0] == "-d" | args[0] == "-D")
             {  
                 byte[] base64EncodedBytes = System.Convert.FromBase64String(args[1]);
                 Console.Write(System.Text.Encoding.UTF8.GetString(base64EncodedBytes));
             }
          }
       }
    }
    


    • 我的命令行用于编译代码C#:

    C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:exe /out:"%Temp%\b64.exe" "%Temp%\b64.cs" /platform:anycpu /unsafe+ /w:0 /o
    



    在此处输入图像描述


    在此处输入图像描述


    • 1
  3. Ricardo Bohner
    2019-11-10T14:54:11+08:002019-11-10T14:54:11+08:00

    Batch 与 unicode 不兼容,因此它会将 ® 识别为 ©,所以我只是在批处理文件中将 ® 更改为 ©,但我想使用 chcp 更改代码页也可以。您要删除名称中没有 ® 的所有文件还是只删除 zip 文件?好吧,如果是所有文件,只需将 for 中的 *.zip 更改为 *:

    @echo off
    Title Delete all files that don't have © in Name
    setlocal EnabledelayedExpansion
    
    Rem Specify the path to the folder here:
    set Folder=%userprofile%\desktop\test
    
    for /r %Folder% %%a in (*.zip) do (
    set Character=%%a
    set Character=!Character:©=!
    IF "!Character!"=="%%a" del /a /f "%%a"
    )
    pause
    
    • 0

相关问题

  • 浏览器不会在 Windows 7 64 位操作系统上获得压缩页面

  • 批量重命名图像文件集

  • Python 的“pass”参数的批处理等价物是什么?

  • 在 Windows 上与 Docker 守护进程通信

  • 资源管理器侧面板中的桌面外壳快捷方式

Sidebar

Stats

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

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve