如何删除文件名中的空格(散装) [英] How to remove spaces from file names (in bulk)

查看:181
本文介绍了如何删除文件名中的空格(散装)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从几千个文件空间(不带下划线代替)散装的Windows?我能做到这一点从DOS命令?

目前

 文件one.mp3
文件two.mp3

所有文件必须成为:

  fileone.mp3
filetwo.mp3


解决方案

下面是一个脚本,它可以有效地批量重命名文件,从名字上剥离所有空格。

 :renameNoSpace [/ R] [FOLDERPATH]
关闭@echo
SETLOCAL disableDelayedExpansion
如果/我%〜1==/ R(
  设置forOption =%〜1%2
  设置INPATH =
)其他(
  设置forOption =
  如果%〜1NEQ,(集INPATH =%〜1 \\),否则设置INPATH =

针对%forOption%%% f由于(%INPATH%*。*)做(
  如果/我%〜F0NEQ%%〜FF(
    设置文件夹= %%〜DPF
    设置文件= %%〜NXF
    SETLOCAL enableDelayedExpansion
    回声仁!的文件夹!!文件! !文件:=!
    仁!文件夹!!文件! !文件:=!
    ENDLOCAL
  )

假设脚本名为 renameNoSpace.bat

renameNoSpace :(无参数)重命名在当前目录下的文件

renameNoSpace / R :重命名在当前目录为根的文件夹树的文件

renameNoSpace MyFolder中:重命名在当前目录中的MyFolder文件目录中的文件

renameNoSpaceC:\\我的文件夹\\:重命名指定的路径文件。行情的使用,因为路径包含空格。

renameNoSpace / R C:\\ :重命名在C中的所有文件:驱动器

How to remove spaces (not replace with underscores) from several thousand files in bulk in Windows? Can I do this from the DOS command?

Currently:

file one.mp3
file two.mp3

All files need to become:

fileone.mp3
filetwo.mp3

解决方案

Here is a script that can efficiently bulk rename files, stripping all spaces from the name.

:renameNoSpace  [/R]  [FolderPath]
@echo off
setlocal disableDelayedExpansion
if /i "%~1"=="/R" (
  set "forOption=%~1 %2"
  set "inPath="
) else (
  set "forOption="
  if "%~1" neq "" (set "inPath=%~1\") else set "inPath="
)
for %forOption% %%F in ("%inPath%* *") do (
  if /i "%~f0" neq "%%~fF" (
    set "folder=%%~dpF"
    set "file=%%~nxF"
    setlocal enableDelayedExpansion
    echo ren "!folder!!file!" "!file: =!"
    ren "!folder!!file!" "!file: =!"
    endlocal
  )
)

Assume the script is called renameNoSpace.bat

renameNoSpace : (no arguments) Renames files in the current directory

renameNoSpace /R : Renames files in the folder tree rooted at the current directory

renameNoSpace myFolder : Renames files in the "myFolder" directory found in the current directory.

renameNoSpace "c:\my folder\" : Renames files in the specified path. Quotes are used because path contains a space.

renameNoSpace /R c:\ : Renames all files on the C: drive.

这篇关于如何删除文件名中的空格(散装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆