|
9527
银牌会员
     努力做坏人
积分 1185
发帖 438
注册 2006-8-28 来自 北京
状态 离线
|
 『楼 主』:
去掉文件名称前的特定字符
使用 LLM 解释/回答一下
这个是我在GOOGLE组上看到的,顺便发到这里供大家学习,虽然局限性很大,不过可以看看。
主要是去掉文件名前的0
处理前:
0000001.txt 00000010.txt 00000011.txt
00000012.txt 00000013.txt 00000014.txt 00000015.txt 00000016.txt
00000017.txt 00000018.txt 00000019.txt 0000002.txt 00000020.txt
0000003.txt 0000004.txt 0000005.txt 0000006.txt 0000007.txt
0000008.txt 0000009.txt
处理后:
1.txt 10.txt 11.txt 12.txt 13.txt
14.txt 15.txt 16.txt 17.txt 18.txt 19.txt 2.txt
20.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt
9.txt
@echo off
for /f "delims=" %%a in ('dir/b *.txt') do call :next %%a
echo Finish...
goto :eof
:next
set pp=%1
:loop
if %pp:~0,1%==0 set pp=%pp:~1%& goto :loop
ren %1 %pp%
This is what I saw on the GOOGLE group, and I sent it here for everyone to study. Although it has great limitations, you can take a look.
Mainly to remove the 0 before the file name
Before processing:
0000001.txt 00000010.txt 00000011.txt
00000012.txt 00000013.txt 00000014.txt 00000015.txt 00000016.txt
00000017.txt 00000018.txt 00000019.txt 0000002.txt 00000020.txt
0000003.txt 0000004.txt 0000005.txt 0000006.txt 0000007.txt
0000008.txt 0000009.txt
After processing:
1.txt 10.txt 11.txt 12.txt 13.txt
14.txt 15.txt 16.txt 17.txt 18.txt 19.txt 2.txt
20.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt
9.txt
@echo off
for /f "delims=" %%a in ('dir/b *.txt') do call :next %%a
echo Finish...
goto :eof
:next
set pp=%1
:loop
if %pp:~0,1%==0 set pp=%pp:~1%& goto :loop
ren %1 %pp%
|

我今后在论坛的目标就是做个超级坏人!!! |
|
2006-12-7 04:12 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
9527兄涉猎很广啊!学习了。
Brother 9527 has a wide range of interests! Learned it.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-7 04:29 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
欣赏~~
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-12-7 08:20 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
如果名字纯粹是楼主所示(类型),貌似还可以利用数字的特性来处理开头的"00....."简化代码:
@echo off
for /f "delims=" %%i in ('dir/b *.txt') do (
echo 正在处理.......
set /a name=%%~ni+0
call ren "%%i" "%%name%%%%~xi"
)
echo 处理完毕
pause
If the name is purely as shown by the owner (type), it seems that the characteristics of numbers can be used to handle the leading "00....." to simplify the code:
@echo off
for /f "delims=" %%i in ('dir/b *.txt') do (
echo Processing.......
set /a name=%%~ni+0
call ren "%%i" "%%name%%%%~xi"
)
echo Processing completed
pause
|
|
2006-12-7 08:42 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
欣赏youxi01兄非常巧妙的方法~:)
太巧合啦,SET /A 居然把这么多的0前缀的 00000020 当成了以0开头的8进制数字了,结果8进制的20正好是10进制的16~:)
C:\TEMP\file>set /a 00000020
16
意外的是那个 00000020.txt 被 SET /A 由 SET认为的8进制转成了10进制的 16.txt 了~:)
不过这只是意外:)
欣赏youxi01兄好玩的实现方法~:)
Appreciate brother youxi01's very clever method~ :)
It's too coincidental that SET /A actually treats so many 0-prefixed 00000020 as octal numbers starting with 0. As a result, octal 20 is exactly 16 in decimal~ :)
C:\TEMP\file>set /a 00000020
16
The unexpected thing is that the 00000020.txt was converted by SET /A from the octal number that SET thought into 16.txt in decimal~ :)
But this is just an accident~ :)
Appreciate brother youxi01's fun implementation method~ :)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-12-7 09:10 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-12-7 09:50 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
 『第 7 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "delims=" %%i in ('dir/b *.txt') do (
echo 正在处理.......
set /a name=1%%~ni%%100000
call ren "%%i" "%%name%%%%~xi"
)
echo 处理完毕
pause
```
@echo off
for /f "delims=" %%i in ('dir/b *.txt') do (
echo Processing.......
set /a name=1%%~ni%%100000
call ren "%%i" "%%name%%%%~xi"
)
echo Processing completed
pause
```
|

我的网络U盘 我的网络第2个U盘
论坛软件下载链接
灵雨飘零论坛
论坛新手必读,所有人的基本行为准则
刷QQ空间人气、留言的小软件 |
|
2006-12-7 09:55 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
set /a 的方法要么受进制的影响容易出错,要么就是难以得知首位0的个数从而不易通过在首位添1再减的方式来求出结果,还是通过探测首位是否为0来决定是否继续抛弃首位的一个0这种方法比较具备通用性。
The method of set /a is either affected by the number system and prone to errors, or it is difficult to know the number of leading zeros, so it is not easy to find the result by adding 1 at the leading position and then subtracting. Still, the method of detecting whether the leading digit is 0 to decide whether to continue to discard one leading 0 is more universal.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-12-7 10:26 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
不好意思,忘记了进制的问题,自己比较粗心(冲动)的性格还是没有改变啊!namejm的说法不错,不过这个问题也不是没有解决的,看看下面的代码还存在什么的问题(解决了进制的问题):
@echo off & echo 正在处理.......
for /f "delims=" %%i in ('dir/b *.txt') do (
set /a name=2%%~ni-1%%~ni
call set /a name=1%%~ni-%%name%%
call rename "%%i" "%%name%%%%~xi"
)
echo 处理完毕
pause
I'm sorry, I forgot about the issue of number bases. My careless (impulsive) personality still hasn't changed! namejm's statement is good, but this problem isn't without a solution. Let's see what other problems there are in the following code (after solving the number base issue):
@echo off & echo Processing.......
for /f "delims=" %%i in ('dir/b *.txt') do (
set /a name=2%%~ni-1%%~ni
call set /a name=1%%~ni-%%name%%
call rename "%%i" "%%name%%%%~xi"
)
echo Processing completed
pause
此帖被 +9 点积分 点击查看详情 评分人:【 namejm 】 | 分数: +4 | 时间:2006-12-7 12:49 | 评分人:【 redtek 】 | 分数: +5 | 时间:2006-12-7 23:19 |
|
|
|
2006-12-7 11:42 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
|
2006-12-7 11:47 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by redtek at 2006-12-7 09:10:
欣赏youxi01兄非常巧妙的方法~:)
太巧合啦,SET /A 居然把这么多的0前缀的 00000020 当成了以0开头的8进制数字了,结果8进制的20正好是10进制皠...
这种取位循环去零法的确很爽, 通用各种情况. 在批处理处理浮点数中也屡试不爽.
关于进制出错的问题, 以前也有过讨论.
http://www.cn-dos.net/forum/viewthread.php?tid=22951&fpage=1&highlight=
Last edited by pengfei on 2006-12-7 at 01:09 PM ]
Originally posted by redtek at 2006-12-7 09:10:
Appreciate the very clever method of user youxi01~ : )
What a coincidence! SET /A actually treats so many 0-prefixed 00000020 as an octal number starting with 0, and the result is that the octal 20 happens to be...
This method of taking digits in a loop to remove zeros is indeed very cool, and it works well in various situations. It has also worked well in dealing with floating-point numbers in batch processing.
Regarding the problem of octal errors, there has been a discussion before.
http://www.cn-dos.net/forum/viewthread.php?tid=22951&fpage=1&highlight=
Last edited by pengfei on 2006-12-7 at 01:09 PM ]
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-12-7 11:57 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
第9楼测试结果:
测试前:
F:\test 的目录
2006-12-06 23:33 <DIR> .
2006-12-06 23:33 <DIR> ..
2006-10-26 23:13 17 NT-CMD.bat
2006-12-06 23:34 2 0001.txt
2006-12-06 23:34 2 0002.txt
2006-12-06 23:34 2 0003.txt
2006-12-06 23:34 2 0004.txt
2006-12-06 23:34 2 0005.txt
2006-12-06 23:34 2 0006.txt
2006-12-06 23:34 2 0007.txt
2006-12-06 23:34 2 0008.txt
2006-12-06 23:34 2 0009.txt
2006-12-06 23:34 2 00010.txt
2006-12-06 23:34 2 00011.txt
2006-12-06 23:34 2 00012.txt
2006-12-06 23:34 2 00013.txt
2006-12-06 23:34 2 00014.txt
2006-12-06 23:34 2 00015.txt
2006-12-06 23:34 2 00016.txt
2006-12-06 23:34 2 00017.txt
2006-12-06 23:34 2 00018.txt
2006-12-06 23:34 2 00019.txt
2006-12-06 23:34 2 00020.txt
2006-12-06 23:34 2 00021.txt
2006-12-06 23:34 2 00022.txt
2006-12-06 23:34 2 00023.txt
2006-12-06 23:34 2 00024.txt
2006-12-06 23:34 2 00025.txt
2006-12-06 23:34 2 00026.txt
2006-12-06 23:34 2 00027.txt
2006-12-06 23:34 2 00028.txt
2006-12-06 23:34 2 00029.txt
2006-12-06 23:34 2 00030.txt
2006-12-06 23:34 2 00031.txt
2006-12-06 23:34 2 00032.txt
2006-12-06 23:34 2 00033.txt
2006-12-06 23:34 2 00034.txt
2006-12-06 23:34 2 00035.txt
2006-12-06 23:34 2 00036.txt
2006-12-06 23:34 2 00037.txt
2006-12-06 23:34 2 00038.txt
2006-12-06 23:34 2 00039.txt
2006-12-06 23:34 2 00040.txt
2006-12-06 23:34 2 00041.txt
2006-12-06 23:34 2 00042.txt
2006-12-06 23:34 2 00043.txt
2006-12-06 23:34 2 00044.txt
2006-12-06 23:34 2 00045.txt
2006-12-06 23:34 2 00046.txt
2006-12-06 23:34 2 00047.txt
2006-12-06 23:34 2 00048.txt
2006-12-06 23:34 2 00049.txt
2006-12-06 23:34 2 00050.txt
51 个文件 117 字节
2 个目录 17,874,583,552 可用字节
测试后:
F:\test 的目录
2006-12-06 23:33 <DIR> .
2006-12-06 23:33 <DIR> ..
2006-12-06 23:38 6 NT-CMD.bat
2006-12-06 23:34 2 1.txt
2006-12-06 23:34 2 2.txt
2006-12-06 23:34 2 3.txt
2006-12-06 23:34 2 4.txt
2006-12-06 23:34 2 5.txt
2006-12-06 23:34 2 6.txt
2006-12-06 23:34 2 7.txt
2006-12-06 23:34 2 8.txt
2006-12-06 23:34 2 9.txt
2006-12-06 23:34 2 10.txt
2006-12-06 23:34 2 11.txt
2006-12-06 23:34 2 12.txt
2006-12-06 23:34 2 13.txt
2006-12-06 23:34 2 14.txt
2006-12-06 23:34 2 15.txt
2006-12-06 23:34 2 16.txt
2006-12-06 23:34 2 17.txt
2006-12-06 23:34 2 18.txt
2006-12-06 23:34 2 19.txt
2006-12-06 23:34 2 20.txt
2006-12-06 23:34 2 21.txt
2006-12-06 23:34 2 22.txt
2006-12-06 23:34 2 23.txt
2006-12-06 23:34 2 24.txt
2006-12-06 23:34 2 25.txt
2006-12-06 23:34 2 26.txt
2006-12-06 23:34 2 27.txt
2006-12-06 23:34 2 28.txt
2006-12-06 23:34 2 29.txt
2006-12-06 23:34 2 30.txt
2006-12-06 23:34 2 31.txt
2006-12-06 23:34 2 32.txt
2006-12-06 23:34 2 33.txt
2006-12-06 23:34 2 34.txt
2006-12-06 23:34 2 35.txt
2006-12-06 23:34 2 36.txt
2006-12-06 23:34 2 37.txt
2006-12-06 23:34 2 38.txt
2006-12-06 23:34 2 39.txt
2006-12-06 23:34 2 40.txt
2006-12-06 23:34 2 41.txt
2006-12-06 23:34 2 42.txt
2006-12-06 23:34 2 43.txt
2006-12-06 23:34 2 44.txt
2006-12-06 23:34 2 45.txt
2006-12-06 23:34 2 46.txt
2006-12-06 23:34 2 47.txt
2006-12-06 23:34 2 48.txt
2006-12-06 23:34 2 49.txt
2006-12-06 23:34 2 50.txt
51 个文件 106 字节
2 个目录 17,874,583,552 可用字节
目前为止,没发现大的问题,成功解决进制的问题。
Post 9 test results:
Before testing:
Directory of F:\test
2006-12-06 23:33 <DIR> .
2006-12-06 23:33 <DIR> ..
2006-10-26 23:13 17 NT-CMD.bat
2006-12-06 23:34 2 0001.txt
2006-12-06 23:34 2 0002.txt
2006-12-06 23:34 2 0003.txt
2006-12-06 23:34 2 0004.txt
2006-12-06 23:34 2 0005.txt
2006-12-06 23:34 2 0006.txt
2006-12-06 23:34 2 0007.txt
2006-12-06 23:34 2 0008.txt
2006-12-06 23:34 2 0009.txt
2006-12-06 23:34 2 00010.txt
2006-12-06 23:34 2 00011.txt
2006-12-06 23:34 2 00012.txt
2006-12-06 23:34 2 00013.txt
2006-12-06 23:34 2 00014.txt
2006-12-06 23:34 2 00015.txt
2006-12-06 23:34 2 00016.txt
2006-12-06 23:34 2 00017.txt
2006-12-06 23:34 2 00018.txt
2006-12-06 23:34 2 00019.txt
2006-12-06 23:34 2 00020.txt
2006-12-06 23:34 2 00021.txt
2006-12-06 23:34 2 00022.txt
2006-12-06 23:34 2 00023.txt
2006-12-06 23:34 2 00024.txt
2006-12-06 23:34 2 00025.txt
2006-12-06 23:34 2 00026.txt
2006-12-06 23:34 2 00027.txt
2006-12-06 23:34 2 00028.txt
2006-12-06 23:34 2 00029.txt
2006-12-06 23:34 2 00030.txt
2006-12-06 23:34 2 00031.txt
2006-12-06 23:34 2 00032.txt
2006-12-06 23:34 2 00033.txt
2006-12-06 23:34 2 00034.txt
2006-12-06 23:34 2 00035.txt
2006-12-06 23:34 2 00036.txt
2006-12-06 23:34 2 00037.txt
2006-12-06 23:34 2 00038.txt
2006-12-06 23:34 2 00039.txt
2006-12-06 23:34 2 00040.txt
2006-12-06 23:34 2 00041.txt
2006-12-06 23:34 2 00042.txt
2006-12-06 23:34 2 00043.txt
2006-12-06 23:34 2 00044.txt
2006-12-06 23:34 2 00045.txt
2006-12-06 23:34 2 00046.txt
2006-12-06 23:34 2 00047.txt
2006-12-06 23:34 2 00048.txt
2006-12-06 23:34 2 00049.txt
2006-12-06 23:34 2 00050.txt
51 File(s) 117 bytes
2 Dir(s) 17,874,583,552 bytes free
After testing:
Directory of F:\test
2006-12-06 23:33 <DIR> .
2006-12-06 23:33 <DIR> ..
2006-12-06 23:38 6 NT-CMD.bat
2006-12-06 23:34 2 1.txt
2006-12-06 23:34 2 2.txt
2006-12-06 23:34 2 3.txt
2006-12-06 23:34 2 4.txt
2006-12-06 23:34 2 5.txt
2006-12-06 23:34 2 6.txt
2006-12-06 23:34 2 7.txt
2006-12-06 23:34 2 8.txt
2006-12-06 23:34 2 9.txt
2006-12-06 23:34 2 10.txt
2006-12-06 23:34 2 11.txt
2006-12-06 23:34 2 12.txt
2006-12-06 23:34 2 13.txt
2006-12-06 23:34 2 14.txt
2006-12-06 23:34 2 15.txt
2006-12-06 23:34 2 16.txt
2006-12-06 23:34 2 17.txt
2006-12-06 23:34 2 18.txt
2006-12-06 23:34 2 19.txt
2006-12-06 23:34 2 20.txt
2006-12-06 23:34 2 21.txt
2006-12-06 23:34 2 22.txt
2006-12-06 23:34 2 23.txt
2006-12-06 23:34 2 24.txt
2006-12-06 23:34 2 25.txt
2006-12-06 23:34 2 26.txt
2006-12-06 23:34 2 27.txt
2006-12-06 23:34 2 28.txt
2006-12-06 23:34 2 29.txt
2006-12-06 23:34 2 30.txt
2006-12-06 23:34 2 31.txt
2006-12-06 23:34 2 32.txt
2006-12-06 23:34 2 33.txt
2006-12-06 23:34 2 34.txt
2006-12-06 23:34 2 35.txt
2006-12-06 23:34 2 36.txt
2006-12-06 23:34 2 37.txt
2006-12-06 23:34 2 38.txt
2006-12-06 23:34 2 39.txt
2006-12-06 23:34 2 40.txt
2006-12-06 23:34 2 41.txt
2006-12-06 23:34 2 42.txt
2006-12-06 23:34 2 43.txt
2006-12-06 23:34 2 44.txt
2006-12-06 23:34 2 45.txt
2006-12-06 23:34 2 46.txt
2006-12-06 23:34 2 47.txt
2006-12-06 23:34 2 48.txt
2006-12-06 23:34 2 49.txt
2006-12-06 23:34 2 50.txt
51 File(s) 106 bytes
2 Dir(s) 17,874,583,552 bytes free
So far, no major problems have been found, and the problem of the number base has been successfully solved.
|
|
2006-12-7 12:40 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
youxi01 和 3742668 的代码有点出人意料,甚是精彩。
The code of youxi01 and 3742668 is a bit unexpected and very wonderful.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-12-7 12:51 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
3742668版主的爽, 直接用0作分隔符. 这种方法应该也可以通用, 妙哉...
The joy of moderator 3742668, directly using 0 as a separator. This method should also be universal, wonderful...
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-12-7 12:54 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
3742668版主的爽!!!斑竹应该多来逛逛,你的代码总是让人耳目一新啊!羡慕+学习!
Last edited by youxi01 on 2006-12-7 at 01:05 PM ]
The pleasure of version 3742668 moderator!!! The moderator should come and take a look more often, your code always makes people feel refreshed! Envy + learning!
Last edited by youxi01 on 2006-12-7 at 01:05 PM ]
|
|
2006-12-7 13:02 |
|