|
tommy725
初级用户
 
积分 36
发帖 14
注册 2007-3-31
状态 离线
|
『楼 主』:
(求助)如何编写一个.bat文件实现文件更名批处理
使用 LLM 解释/回答一下
我遇到一个问题,比如,我有几百个.pdf文件
例如: central aaa 01.pdf
akurss bbs 99.pdf
sskpk p12 980 ok.pdf
airchina lufthansa uk mu500.pdf
92 years anniver.pdf
.........
我想做的是编一个批处理文件xxx.cmd 运行一次可以把以上所有pdf文件中的"空格"自动改为"-". 运行xxx.cmd文件后,以上PDF文件即更名为以下并保存:
central-aaa-01.pdf
akurss-bbs-99.pdf
sskpk-p12-980-ok.pdf
airchina-lufthansa-uk-mu500.pdf
92-years-anniver.pdf
.........
请问如何编写,能否给出列子,谢谢啊
Last edited by tommy725 on 2007-4-2 at 06:55 AM ]
I encountered a problem. For example, I have hundreds of.pdf files, such as:
central aaa 01.pdf
akurss bbs 99.pdf
sskpk p12 980 ok.pdf
airchina lufthansa uk mu500.pdf
92 years anniver.pdf
.........
What I want to do is to compile a batch file xxx.cmd. Running it once can automatically change the "spaces" in all the above.pdf files to "-". After running the xxx.cmd file, the above PDF files will be renamed as follows and saved:
central-aaa-01.pdf
akurss-bbs-99.pdf
sskpk-p12-980-ok.pdf
airchina-lufthansa-uk-mu500.pdf
92-years-anniver.pdf
.........
How to write it? Can you give an example? Thank you.
Last edited by tommy725 on 2007-4-2 at 06:55 AM ]
|
|
2007-3-31 18:11 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
|
2007-3-31 18:18 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
   『第 3 楼』:
使用 LLM 解释/回答一下
这个
- @echo off
- for /f "delims=" %%a in ('dir /b /a *.pdf') do set "old_name=%%a" &call :re_name
- goto exit
- :re_name
- set "new_name=%old_name: =-%"
- ren "%old_name%" "%new_name%"
- :exit
BJSH发表于: 2007-03-31 09:37
Last edited by bjsh on 2007-3-31 at 09:47 AM ]
This is the original content in the quote section:
- @echo off
- for /f "delims=" %%a in ('dir /b /a *.pdf') do set "old_name=%%a" &call :re_name
- goto exit
- :re_name
- set "new_name=%old_name: =-%"
- ren "%old_name%" "%new_name%"
- :exit
BJSH发表于: 2007-03-31 09:37
Last edited by bjsh on 2007-3-31 at 09:47 AM ]
|
|
2007-3-31 22:44 |
|
|
zzhh612
中级用户
  
积分 278
发帖 103
注册 2006-10-21
状态 离线
|
|
2007-3-31 23:12 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我自己试着怎么没问题呢??
ls的说一下出错信息
Why is there no problem when I try it myself?? Please tell me the error message.
|
|
2007-4-1 00:35 |
|
|
tommy725
初级用户
 
积分 36
发帖 14
注册 2007-3-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
非常谢谢bjsh,我试一下看看.不过我还是看不懂,你如果能给我解释一下每句的含义或者功能,那就更加感谢了.
Thanks a lot, bjsh. I'll give it a try. But I still don't understand. If you can explain the meaning or function of each sentence, I would be even more grateful.
|
|
2007-4-1 05:59 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %%a in ('dir /b /a *.pdf') do set "old_name=%%a" &call :re_name
对于这一句话?想问个问题?
('dir /b /a *.pdf')里面的参数是不是只会执行一次?然后把把所有变量放内存里?等程序一个一个的读取?
当里面读取的内容非常多的时候。会不会造成机器假死?
对于这一句话?想问个问题?
('dir /b /a *.pdf')里面的参数是不是只会执行一次?然后把把所有变量放内存里?等程序一个一个的读取?
当里面读取的内容非常多的时候。会不会造成机器假死?
For the sentence? Want to ask a question?
Are the parameters inside ('dir /b /a *.pdf') only executed once? Then put all variables into memory? Wait for the program to read one by one?
When there are a lot of content read inside. Will it cause the machine to freeze?
|

知,不觉多。不知,乃求知 |
|
2007-4-1 07:49 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
刚才写错了.
@echo off
setlocal enabledelayedexpansion
for %%h in (*.pdf) do (
set str=%%h
set str=!str: =-!
ren "%%h" "!str!")
Last edited by huzixuan on 2007-4-1 at 08:54 AM ]
Just now I made a mistake.
@echo off
setlocal enabledelayedexpansion
for %%h in (*.pdf) do (
set str=%%h
set str=!str: =-!
ren "%%h" "!str!")
Last edited by huzixuan on 2007-4-1 at 08:54 AM ]
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-4-1 08:50 |
|
|
tommy725
初级用户
 
积分 36
发帖 14
注册 2007-3-31
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
谢谢大家,我可不可以这样测试啊,edit file.cmd,然后把代码写进去保存,然后在所在文件夹下运行这个文件.所在文件夹下有三个测试的.pdf文档.但是这个结果怎么出现这个啊:
a duplicate file name exists,or the file can not be found
a duplicate file name exists,or the file can not be found
a duplicate file name exists,or the file can not be found
Thank you everyone, can I test like this? Edit file.cmd, then write the code in and save it, then run this file in the current folder. There are three test.pdf documents in the current folder. But why does this result appear:
a duplicate file name exists,or the file can not be found
a duplicate file name exists,or the file can not be found
a duplicate file name exists,or the file can not be found
|
|
2007-4-1 17:43 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
直接运行我写的那个;也出现这种错误吗???
Does directly running the one I wrote also have this kind of error???
|
|
2007-4-1 22:49 |
|
|
wuwuwuming
初级用户
 
积分 37
发帖 18
注册 2007-4-1
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
好是好,可是看不懂,真是郁闷~~~~
It's good, but I can't understand it. It's really frustrating~~~~
|
|
2007-4-1 23:05 |
|
|
tommy725
初级用户
 
积分 36
发帖 14
注册 2007-3-31
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
我运行了
@echo off
for /f "delims= " %%a in ('dir /b/a *.pdf') do
set "old_name=%%a" &call :re_name
goto exit
:re_name
set "new_name=%old_name:=-%"
ren "%old_name%" "%new_name%"
:exit
运行后说命令的语法不正确
the syntax of the command is incorrect.
I ran
@echo off
for /f "delims= " %%a in ('dir /b/a *.pdf') do
set "old_name=%%a" &call :re_name
goto exit
:re_name
set "new_name=%old_name:=-%"
ren "%old_name%" "%new_name%"
:exit
After running, it said the syntax of the command is incorrect.
|
|
2007-4-2 19:54 |
|
|
qingfushuan
高级用户
   
积分 502
发帖 327
注册 2006-12-30
状态 离线
|
『第 13 楼』:
试试这个
使用 LLM 解释/回答一下
我刚才写的,经测试可以更名的
@echo off&setlocal enabledelayedexpansion
for /f "delims=." %%a in ('dir /a-d /b *.pdf') do (
set str=%%a
set str=!str: =-!
ren "%%a".pdf !str!.pdf
)
pause
但是你的sskpk p12 980 ok.pdf有两个空格所以更名出来就是
sskpk--p12-980-ok.pdf了,这样子将就用可以了不
What I wrote just now, which can be renamed after testing
@echo off&setlocal enabledelayedexpansion
for /f "delims=." %%a in ('dir /a-d /b *.pdf') do (
set str=%%a
set str=!str: =-!
ren "%%a".pdf !str!.pdf
)
pause
But your sskpk p12 980 ok.pdf has two spaces, so the renamed one will be sskpk--p12-980-ok.pdf. Is it okay to use it like this
|
|
2007-4-2 21:56 |
|
|
tommy725
初级用户
 
积分 36
发帖 14
注册 2007-3-31
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
两个空格是我输入错误,如果可以空格变"-"就可以
Two spaces are my input error. If spaces can be changed to "-", it's okay.
|
|
2007-4-2 22:35 |
|
|
kcdsw
中级用户
  
积分 404
发帖 179
注册 2006-3-30
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
ren "* *.pdf" "*-*.pdf"
ren "* *.pdf" "*-*.pdf"
|
|
2007-4-2 22:42 |
|