查找并重命名没有扩展名的文件? [英] 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屋!