返回列表 发帖

[文件操作] 批处理怎么删除文件夹中文件名的中文符号?

怎么删除文件夹中文件名的中文符号

回复 1# xuhuangbin


请给一个真实的例子说明一下你的需求吧,比如操作之前是怎样的,操作之后变成啥样?
如果需要上传文件,请用使用网盘。

如果需要上传截图,可以找个图床,例如:
http://bbs.bathome.net/thread-60985-1-1.html
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

rem 另存为 ANSI 编码 bat
' & cls & cscript.exe /nologo /e:vbscript "%~f0" %* & pause & exit /b
p = "."    '当前路径。可以指定其它路径,比如 d:\test\
Set oWshShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
p = oFSO.GetAbsolutePathName(p)
oWshShell.CurrentDirectory = p
For Each i In oFSO.GetFolder(p).Files
    s = oFSO.GetFileName(i)
    t = ""
    For j = 1 To Len(s)
        If CLng("&H" & Hex(Asc(Mid(s, j, 1)))) < 127 Then t = t & Mid(s, j, 1)
    Next
    If Not oFSO.FileExists(t) Then oFSO.MoveFile s, t
Next
wsh.Echo "ok"COPY
只保留ascii编码的字符
只处理当前文件夹下的文件
如果同名文件已存在则跳过

QQ 20147578

TOP

本帖最后由 aloha20200628 于 2024-11-25 15:42 编辑

回复 1# xuhuangbin

以下代码存为 test.bat 运行》剔除当前目录下每个文件名中的中文字符(忽略只有中文字符的文件名)...
@echo off &for /f "delims=" %%F in ('dir/b/a-d') do (
   set "F=%%F" &set "nF=%%~nF" &setlocal enabledelayedexpansion
   call :cutHZ
   if defined _nF if "!_nF!" neq "%%~nF" (ren "!F!" "!_nF!%%~xF")
   endlocal
) 2>nul
pause&exit/b
:cutHZ
   if "!nF!"=="" (exit/b) else (
      set "c=!nF:~,1!" &if "!c!" leq "Z" (set "_nF=!_nF!!c!")
      set "nF=!nF:~1!" &goto :cutHZ
   )
   exit/bCOPY

TOP

返回列表