批处理文件,用于用文件名中的空格替换点 [英] batch-file for replacing dots with spaces in file names

查看:194
本文介绍了批处理文件,用于用文件名中的空格替换点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在嵌套文件夹中有一些文件,它们的名称中有一些圆点,我想将它们转换为空格.例如,转换

I have some files in nested folders with some dots in their name which I want to convert them into spaces. For example convert

802.11.Wireless.LAN.Fundamentals.Cisco.Press.eBook-kB.pdf

802 11 Wireless LAN Fundamentals Cisco Press eBook-kB.pdf

请注意,扩展名的最后一个点(在PDF之前)不应删除,因此我不能使用

Notice that the final dot for extension (here before PDF) should not be removed, so I cannot use this script to do this task.

推荐答案

@echo off
    setlocal enableextensions disabledelayedexpansion

    set "root=c:\some\where"

    for /r "%root%" %%a in ("*.?*.pdf") do (
        set "filename=%%~na"
        setlocal enabledelayedexpansion 
        for %%f in ("!filename:.= !") do (
            endlocal  
            echo ren "%%~fa" "%%~f%%~xa"
        )
    )

这将在指示的文件夹下递归搜索扩展名为.pdf的文件,该文件至少包含两个点.对于找到的每个文件,文件名中的附加点(不包括扩展名)将替换为空格.

This will recursively search under the indicated folder for files with .pdf extensions, that include at least two dots. For each file found, aditional dots in the file name (extension excluded) are replaced with a space.

为避免文件名或路径中带有感叹号的问题,在执行重命名操作之前,启用了延迟扩展(需要在块中修改变量并访问更改的值)以删除点并被禁用.

To avoid problems with exclamation points in file names or paths, delayed expansion (needed to modify a variable inside a block and access the changed value) is enabled to remove the dots and disabled before executing the rename operation.

重命名操作仅回显到控制台.如果输出正确,请删除ren

Rename operations are only echoed to console. If the output is correct, remove the echo command that precedes the ren

这篇关于批处理文件,用于用文件名中的空格替换点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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