![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-09 02:09 |
共 47,811 主题排行 / 349,895 发帖 / 今日 0 篇 / 48,253 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » N多文件进行批量的固定长度回车并删掉空格的问题 |
| 可打印版本 2,457 / 25 |
| 第1楼 zhengruijian | 发表于 2008-06-01 12:48 |
| 初级用户 发帖 24 积分 54 | |
|
N多文件进行批量的固定长度回车并删掉空格的问题 跪求大侠,我实在是搞不定了.请你们帮忙啊!!!!多谢了!!!..
请大侠指点迷津! 我想对一个文件夹下的所有文件进行固定字符长度的回车.(30个汉字的长度) 在整理完长度后把里面的空格行全都删除掉.再保存,原文件名不变. 应该怎么做啊? 多谢啦!!!!!!!!!!!! 我只找到了下面这个程序只能执行一个文件,而且还不能保存. @echo off for /f "delims=" %%a in (yourtext.txt) do ( set var=%%a setlocal enabledelayedexpansion set var=!var: =! if not "!var!"=="" set var=!var: =! if not "!var!"=="" echo !var! endlocal ) pause 我要处理的范文如下 : 8、 I Apologize. 我很抱歉。 A: Jessie, I’m afraid I can’t come back home for dinner tonight. 杰茜,我恐怕今晚不能回家吃晚饭了。 B: Not back home for dinner again? That’s the third time this week! 又不回家吃晚饭?这个星期你已经是第三次了这样了! A: I’m sorry. Our company has just opened. There are always too many things to handle. You know that. 对不起。我们的公司刚刚开业,总是有太多事情要处理,这你是知道的。 B: You don’t have to explain. Suit yourself. 你不必解释了。随便你。 A: I apologize. You have my word, I’ll spend some time with you on the weekend. I promise. 很抱歉。我向你保证,周末抽时间来陪你。我发誓。 B: We’ll see. 再说吧。 A: Thank you for understanding. I promise I’ll make it up to you. 谢谢你能理解。我保证一定给你补上。 A: Sam, you’ve got to forgive me. 山姆,你得原谅我。 B: Forgive you for what? 原谅你什么? A: I used your computer. And I’m afraid I’ve erased your personal files accidentally. 我用了你的电脑。恐怕我不小心把你的私人文件删掉了。 B: No! Are you kidding me? 不!你跟我开玩笑? A: I’m afraid not. I apologize. 不是。我很抱歉。 B: I can’t believe it! I have all my important personal documents stored in that computer. It’s no laughing matter. 我简直不敢相信!我将所有重要的私人资料都存入电脑了。这可不是闹着玩的。 A: I told you I’m sorry. What can I do to make it up to you? 我都跟你道歉了。我怎样做才能弥补我的过错? B: Well, you should be sorry! Don’t ever use my computer again! You can’t do anything now, it’s too late! 你应该道歉!再也不许用我的电脑了!现在你做什么都没有用了,已经太迟了! |
|
| 第2楼 slore | 发表于 2008-06-01 14:26 |
| 铂金会员 发帖 2,478 积分 5,212 | |
|
findstr好像有空行过滤吧
|
|
| 第3楼 moniuming | 发表于 2008-06-01 16:12 |
| 银牌会员 发帖 574 积分 1,335 来自 广西 | |
|
楼上有笔误吧,for才过滤空行
|
|
| 第4楼 clonecd | 发表于 2008-06-01 16:55 |
| 初级用户 发帖 46 积分 94 | |
|
标题说删除空格,文章里面说删除空格行,一开始还真不知道是什么意思。
[ Last edited by clonecd on 2008-6-1 at 04:57 PM ] |
|
| 第5楼 terse | 发表于 2008-06-01 17:08 |
| 银牌会员 发帖 946 积分 2,404 | |
|
因为有中英文 我是这样处理的:
汗我以为要删空格 改吧 [ Last edited by terse on 2008-6-1 at 05:50 PM ] |
|
| 第6楼 moniuming | 发表于 2008-06-01 19:54 |
| 银牌会员 发帖 574 积分 1,335 来自 广西 | |
|
to:5楼
运行结果: E:\games\test>1 把最后一个括号去掉后没有提示,直接退出.
[ Last edited by moniuming on 2008-6-1 at 07:55 PM ] |
|
| 第7楼 slore | 发表于 2008-06-01 20:49 |
| 铂金会员 发帖 2,478 积分 5,212 | |
|
=。=我没有打错。。。 @echo off
findstr "." Slore.txt>erolS.txt ::下面的空格数你自己可以多打点,按你的格式 ::来看连续这么多空格应该够了。 findstr /v /c:" " erolS.txt>Slore.txt echo 处理完毕! pause>nul [ Last edited by slore on 2008-6-1 at 08:55 PM ] |
|
| 第8楼 zhengruijian | 发表于 2008-06-01 20:56 |
| 初级用户 发帖 24 积分 54 | |
|
谢谢各位大哥的帮助.
用了达人的这个代码处理得很好,只是不能处理汉字,英文倒是排得好好的.不知道怎么样能做成处理汉字的?就是说30个汉字的长度也换行.下面的代码该如何改善一下才能做到呢? @echo off ::放在要处理的目录里运行 ::不能处理汉字(即无论汉字或英文, 超过60个才能处理) ::注意: 非空格行不能以空格开头 setlocal enabledelayedexpansion for /f "delims=" %%i in ('dir /b/a-d "*.txt"') do ( type nul>temp.txt for /f "delims=" %%m in ('type "%%i"') do ( set "str=%%m" if "!str:~0,1!"==" " (set "str=!str: =!") else (call :cut) ) move /y temp.txt "%%i" ) goto :eof :cut set "var=%str:~0,60%" >>temp.txt echo %var% set str=%str:~60% if not "%str%"=="" goto :cut 我用上面这个程序把范文处理后是这样的: 8、 I Apologize. 我很抱歉。 A: Jessie, I’m afraid I can’t come back home for dinner toni ght. 杰茜,我恐怕今晚不能回家吃晚饭了。 B: Not back home for dinner again? That’s the third time thi s week 又不回家吃晚饭?这个星期你已经是第三次了这样了! A: I’m sorry. Our company has just opened. There are always too many things to handle. You know that. 对不起。我们的公司刚刚开业,总是有太多事情要处理,这你是知道的。 B: You don’t have to explain. Suit yourself. 你不必解释了。随便你。 A: I apologize. You have my word, I’ll spend some time with you on the weekend. I promise. 很抱歉。我向你保证,周末抽时间来陪你。我发誓。 B: We’ll see. 再说吧。 A: Thank you for understanding. I promise I’ll make it up to you. 谢谢你能理解。我保证一定给你补上。 A: Sam, you’ve got to forgive me. 山姆,你得原谅我。 B: Forgive you for what? 原谅你什么? A: I used your computer. And I’m afraid I’ve erased your per sonal files accidentally. 我用了你的电脑。恐怕我不小心把你的私人文件删掉了。 B: No Are you kidding me? 不!你跟我开玩笑? A: I’m afraid not. I apologize. 不是。我很抱歉。 B: I can’t believe it I have all my important personal docum ents stored in that computer. It’s no laughing matter. 我简直不敢相信!我将所有重要的私人资料都存入电脑了。这可不是闹着玩的。 A: I told you I’m sorry. What can I do to make it up to you? 我都跟你道歉了。我怎样做才能弥补我的过错? B: Well, you should be sorry You can’t do anything now, it’s too late 你应该道歉!再也不许用我的电脑了!现在你做什么都没有用了,已经太迟了! |
|
| 第9楼 slore | 发表于 2008-06-01 21:00 |
| 铂金会员 发帖 2,478 积分 5,212 | |
|
。。。原来是这个意思。。。一个汉字算2个字节还是要怎么样呀?
|
|
| 第10楼 zhengruijian | 发表于 2008-06-01 21:12 |
| 初级用户 发帖 24 积分 54 | |
|
@echo off
::放在要处理的目录里运行 ::不能处理汉字(即无论汉字或英文, 超过60个才能处理) ::注意: 非空格行不能以空格开头 setlocal enabledelayedexpansion for /f "delims=" %%i in ('dir /b/a-d "*.txt"') do ( type nul>temp.txt for /f "delims=" %%m in ('type "%%i"') do ( set "str=%%m" if "!str:~0,1!"==" " (set "str=!str: =!") else (call :cut) ) move /y temp.txt "%%i" ) goto :eof :cut set "var=%str:~0,30%" >>temp.txt echo %var% set str=%str:~30% if not "%str%"=="" goto :cut 这个程序扩展性不错啊.我把里面的60全改为30后,处理成如下这个样子,可是英文看起来是真的很不爽啊.一句话搞成了好几行. 我想好好排下版的目的就是把这些文本做成LRC的歌词格式.我有配套的MP3.如果做好了哪位兄弟要的话,我可以传给你们啊.大家相互帮忙一下啊! 哪位大哥能把这个程序改善下啊.就是排版出来都是30个汉字长度才回车.那样大家都看得舒服些. 8、 I Apologize. 我很抱歉。 A: Jessie, I’m afraid I can’t come back home for dinner toni ght. 杰茜,我恐怕今晚不能回家吃晚饭了。 B: Not back home for dinner ag ain? That’s the third time thi s week 又不回家吃晚饭?这个星期你已经是第三次了这样了! A: I’m sorry. Our company has just opened. There are always too many things to handle. You know that. 对不起。我们的公司刚刚开业,总是有太多事情要处理,这你是知道 的。 B: You don’t have to explain. Suit yourself. 你不必解释了。随便你。 A: I apologize. You have my wo rd, I’ll spend some time with you on the weekend. I promise. 很抱歉。我向你保证,周末抽时间来陪你。我发誓。 B: We’ll see. 再说吧。 A: Thank you for understanding . I promise I’ll make it up to 谢谢你能理解。我保证一定给你补上。 A: Sam, you’ve got to forgive me. 山姆,你得原谅我。 B: Forgive you for what? 原谅你什么? A: I used your computer. And I ’m afraid I’ve erased your per sonal files accidentally. 我用了你的电脑。恐怕我不小心把你的私人文件删掉了。 B: No Are you kidding me? 不!你跟我开玩笑? A: I’m afraid not. I apologize . 不是。我很抱歉。 B: I can’t believe it I have a ll my important personal docum ents stored in that computer. It’s no laughing matter. 我简直不敢相信!我将所有重要的私人资料都存入电脑了。这可不是 闹着玩的。 A: I told you I’m sorry. What can I do to make it up to you? 我都跟你道歉了。我怎样做才能弥补我的过错? B: Well, you should be sorry Y ou can’t do anything now, it’s 你应该道歉!再也不许用我的电脑了!现在你做什么都没有用了,已 经太迟了! |
|
| 第11楼 zhengruijian | 发表于 2008-06-01 21:14 |
| 初级用户 发帖 24 积分 54 | |
|
忘了说了,上面的范文是疯狂英语里面的一篇..希望大家帮忙,我想学好英语.
[ Last edited by zhengruijian on 2008-6-1 at 09:21 PM ] |
|
| 第12楼 terse | 发表于 2008-06-01 22:09 |
| 银牌会员 发帖 946 积分 2,404 | |
Originally posted by moniuming at 2008-6-1 19:54: 怎么回事 我这里可以的嘛 下面是处理后的: |
|
| 第13楼 slore | 发表于 2008-06-01 22:15 |
| 铂金会员 发帖 2,478 积分 5,212 | |
|
?貌似没有除了的样子呀=。=
|
|
| 第14楼 moniuming | 发表于 2008-06-01 22:28 |
| 银牌会员 发帖 574 积分 1,335 来自 广西 | |
|
弄得我头都大了(借用5楼的判断方法
![]() ![]() ),这次应该没问题了,汗......... |
|
| 第15楼 terse | 发表于 2008-06-01 22:33 |
| 银牌会员 发帖 946 积分 2,404 | |
|
我刚才 发出来怎么这样啊 这样呢
8、 I Apologize. 我很抱歉。 A: Jessie, I’m afraid I can’t come back home for dinner toni ght. 杰茜,我恐怕今晚不能回家吃晚饭了。 B: Not back home for dinner again? That’s the third time thi s week 又不回家吃晚饭?这个星期你已经是第三次了这样了! A: I’m sorry. Our company has just opened. There are always too many things to handle. You know that. 对不起。我们的公司刚刚开业,总是有太多事情要处理,这你是知道 的。 B: You don’t have to explain. Suit yourself. 你不必解释了。随便你。 A: I apologize. You have my word, I’ll spend some time with you on the weekend. I promise. 很抱歉。我向你保证,周末抽时间来陪你。我发誓。 B: We’ll see. 再说吧。 A: Thank you for understanding. I promise I’ll make it up to you. 谢谢你能理解。我保证一定给你补上。 A: Sam, you’ve got to forgive me. 山姆,你得原谅我。 B: Forgive you for what? 原谅你什么? A: I used your computer. And I’m afraid I’ve erased your per sonal files accidentally. 我用了你的电脑。恐怕我不小心把你的私人文件删掉了。 B: No! Are you kidding me? 不!你跟我开玩笑? A: I’m afraid not. I apologize. 不是。我很抱歉。 B: I can’t believe it! I have all my important personal docu ments stored in that computer. It’s no laughing matter. 我简直不敢相信!我将所有重要的私人资料都存入电脑了。这可不是 闹着玩的。 A: I told you I’m sorry. What can I do to make it up to you? 我都跟你道歉了。我怎样做才能弥补我的过错? B: Well, you should be sorry! Don’t ever use my computer aga in |
|
| 1 2 下一页 |
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |