一个文件夹中有2种格式的文件,分别是xls和pdf文件。
xls和pdf文件都是按照名称排列的,两者的个数相等。
现在要把xls文件的名称复制给pdf文件。
请问如何编写???
例如:
xls文件有(你.xls;我.xls;他.xls)
pdf文件有(1.pdf;2.pdf;3.pdf)
现要把Ppdf文件名改成(你.pdf;我.pdf;他.pdf)
请教高手出招。。。
-----------------------------------------
for %%i in (*.pdf) do (
for %%j in (*.xls) do (
ren "%%i" "%%~nj.pdf">nul 2>nul
)
)
------------------------------------------
存在一点小问题,就是没有排序,有些文件还是不能正常转换。
而且我想要若干个文件夹内都要使用该如何?
比如文件夹A中有
xls文件有(你.xls;我.xls;他.xls)
pdf文件有(1.pdf;2.pdf;3.pdf)
文件夹B中有
xls文件有(你.xls;我.xls;他.xls)
pdf文件有(1.pdf;2.pdf;3.pdf)
文件夹C中有
xls文件有(你.xls;我.xls;他.xls)
pdf文件有(1.pdf;2.pdf;3.pdf)
这样该如何实现?
批处理文件重命名
答案:2 悬赏:0
解决时间 2021-11-17 17:00
- 提问者网友:梧桐不渝
- 2021-11-16 16:50
最佳答案
- 二级知识专家网友:何以畏孤独
- 2021-11-16 17:59
迟来的答案~
将以下代码保存为批处理(.bat)文件,放到要更名的文件夹内运行测试,测试成功后去除代码中的echo 运行本批处理即可。
------------------
@echo off&setlocal Enabledelayedexpansion
set n=0,w=0
for /f "delims=" %%a in ('dir /a-d/b/on *.xls') do (
set /a n+=1
set xls!n!=%%~na
)
for /f "delims=" %%b in ('dir /a-d/b/on *.pdf') do call:RR %%b
pause
:RR
set /a w+=1
echo ren %1 !xls%w%!.pdf
goto:eof
----------------
补充:
包括子文件夹内的
@echo off&setlocal Enabledelayedexpansion
set n=0,w=0
for /f "delims=" %%a in ('dir /a-d/s/b/on *.xls') do (
set /a n+=1
set xls!n!=%%~na
)
for /f "delims=" %%b in ('dir /a-d/b/s/on *.pdf') do set R1=%%b&call:RR
exit
:RR
set /a w+=1
ren "%R1%" "!xls%w%!.pdf"
goto:eof
望楼主多测试。
将以下代码保存为批处理(.bat)文件,放到要更名的文件夹内运行测试,测试成功后去除代码中的echo 运行本批处理即可。
------------------
@echo off&setlocal Enabledelayedexpansion
set n=0,w=0
for /f "delims=" %%a in ('dir /a-d/b/on *.xls') do (
set /a n+=1
set xls!n!=%%~na
)
for /f "delims=" %%b in ('dir /a-d/b/on *.pdf') do call:RR %%b
pause
:RR
set /a w+=1
echo ren %1 !xls%w%!.pdf
goto:eof
----------------
补充:
包括子文件夹内的
@echo off&setlocal Enabledelayedexpansion
set n=0,w=0
for /f "delims=" %%a in ('dir /a-d/s/b/on *.xls') do (
set /a n+=1
set xls!n!=%%~na
)
for /f "delims=" %%b in ('dir /a-d/b/s/on *.pdf') do set R1=%%b&call:RR
exit
:RR
set /a w+=1
ren "%R1%" "!xls%w%!.pdf"
goto:eof
望楼主多测试。
全部回答
- 1楼网友:不服输的倔强
- 2021-11-16 18:38
for %%i in (*.pdf) do (
for %%j in (*.xls) do (
ren "%%i" "%%~nj.pdf">nul 2>nul
)
)
备份一下文件,错了我可不负责哦
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯