批量将带空格的文件名分配给变量 [英] Batch to assign filename with spaces to variable

查看:30
本文介绍了批量将带空格的文件名分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人回答了这个问题,我深表歉意,但我已经找了一个星期来解决这个问题,但无济于事.我正在尝试创建一个批处理文件,该文件在文件夹中查找特定文件 ext(永远只有一个),将该文件的名称分配给一个变量,然后根据变量名称将该文件重命名为新名字.

Many apologies if this has been answered but I've searched for a week to get this right and to no avail. I'm trying to create a batch file that looks in a folder for a specific file ext (there will only ever be one), assigns the name of that file to a variable, and then renames the file based on the variable name to a new name.

到目前为止我所拥有的:

What I have so far:

for /F %%x in ('dir /b *.html') do set "FileName=%%x"
echo %FileName%
ren %FileName% test.html

因为每个文件名中都会有空格,所以这个解决方案只会将文件名的第一个单词分配给 %FileName% ,因此重命名行将不起作用,因为它找不到文件夹中的文件名 <>.html

Because each filename is going to have spaces in it, this solution will only assign the first word of the filename to %FileName% and thus the rename line will not work because it won't find a filename in the folder with <<FirstWordofFilename>>.html

我的问题是,如何将一个包含空格的名称分配给变量?

My question is, how do I assign a name with spaces in it to a variable?

再次道歉,如果有人回答了这个问题,尽管它必须是一个常见问题,但我真的找不到任何地方.

Again, apologies if this has been answered, I really couldn't find it anywhere despite it having to be a common problem.

任何帮助都会很棒.

谢谢!

推荐答案

for /F "delims=" %%x in ('dir /b *.html') do set "FileName=%%x"
echo "%FileName%"
ren "%FileName%" "test.html"

for /?

从提示获取更多信息.

这篇关于批量将带空格的文件名分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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