查找和重命名没有扩展名的文件? [英] Find and rename files with no extension?
问题描述
所以,我有一堆没有扩展名的文件.我想编写一个 Windows 批处理脚本:
So, I've got a bunch of files with no extension. I want to write a windows batch script that will:
- 查找没有扩展名的文件(在指定文件夹中)
- 在文件名末尾添加 .bla
我是一个 Windows 批处理脚本菜鸟,我什至不知道从哪里开始.建议?
I'm such a windows batch script noob I don't even know where to start. Suggestions?
推荐答案
对于 Windows 批处理文件,这只会将没有扩展名的文件重命名为 .bla 扩展名:
For windows batch files, this will rename only files with no extension to the .bla extension:
rename *. *.bla
注意第一个参数是一个星号和一个点:*.
Notice the first argument is a star and a dot: *.
第二个参数是:*.bla
The second argument is: *.bla
起始点 (*.) 组合表示在此上下文中没有扩展名的文件.
The start dot (*.) combination represents files with no extensions in this context.
之前:
06/21/2009 11:57 PM 6 test
06/21/2009 11:57 PM 7 test.exe
06/21/2009 11:57 PM 7 test2
之后:
06/21/2009 11:57 PM 6 test.bla
06/21/2009 11:57 PM 7 test.exe
06/21/2009 11:57 PM 7 test2.bla
附加说明:相反的命令行会将所有 .bla 文件重命名为无扩展名文件.
Additional note: The opposite commandline would rename all .bla files into no extension files.
编辑:
对于跨子目录递归重命名没有扩展名的文件(不支持路径中的空格):
For recursively renaming files with no extension across subdirectories (doesn't support spaces in paths):
@echo off
FOR /F %%i in ('dir /b/s/A-d') DO (
if "%%~xi" == "" rename "%%~fi" "%%~ni.bla"
)
对于跨子目录递归重命名没有扩展名的文件(支持路径中的空格):
For recursively renaming files with no extension across subdirectories (supports spaces in path):
@echo off
for /f "tokens=* delims= " %%i in ('dir /b/s/A-d') DO (
if "%%~xi" == "" rename "%%~fi" "%%~ni.bla"
)
这篇关于查找和重命名没有扩展名的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!