无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 3762|回复: 13
打印 上一主题 下一主题

dos命令求教。写个批处理

[复制链接]
跳转到指定楼层
1#
发表于 2010-10-26 17:08:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
例如
x:\windows\1.txt  我改名为2.txt  (x代表我不知道这个盘符是什么)

批处理实现。
寻找 所有硬盘分区下 \windows\下有没有1.txt 如果有的话改名为2.txt

看批处理实在是好难噢。


已经解决。代码如下。
for %%c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
        if exist %%c:\windows\1.txt ren %%c:\windows\1.txt 2.txt
                    )

回2楼。-dos时代菜鸟 按你的来不过不行噢。
回9楼。 已经成功了噢!-dos批处理某些时刻很强大!
感谢版主大人的热心解答。

又有问提了。汗。老是提问。都不好意思了。

如果我寻找两个文件。并改名呢?
for %%c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
        if exist %%c:\WINDOWS\system32\1.exe ren %%c:\WINDOWS\system32\1.exes
for %%%c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
        if exist %%%c:\WINDOWS\system32\drivers\2.sys %%%c:\WINDOWS\system32\drivers\2.syss


这样貌似是不行的。

[ 本帖最后由 tianxiashuma 于 2010-10-27 18:59 编辑 ]

12.jpg (33.91 KB, 下载次数: 50)

谢谢时代菜鸟的指教,不过还是不行

谢谢时代菜鸟的指教,不过还是不行
2#
发表于 2010-10-26 18:27:55 | 只看该作者
不用批处理,一句话就可以解决

写得着急居然把 ren 命令写错了,现在纠正。
这样简单的命题,不用编辑批处理的,就用这样一句话就可以解决。

  1. for  %c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (if exist %c:\windows\1.txt ren  %c:\windows 1.txt %c:\windows\2.txt)
复制代码

[ 本帖最后由 dos时代菜鸟 于 2010-10-27 19:01 编辑 ]
回复

使用道具 举报

3#
 楼主| 发表于 2010-10-26 18:56:17 | 只看该作者

回复 #2 dos时代菜鸟 的帖子

c:\windows\ 下没有1.txt 噢。我是放在d盘的。。
回复

使用道具 举报

4#
 楼主| 发表于 2010-10-26 18:59:43 | 只看该作者
傻方法。。琢磨出的。。
ren c:\WINDOWS\1.txt 2.txt
ren d:\WINDOWS\1.txt 2.txt
ren e:\WINDOWS\1.txt 2.txt
ren f:\WINDOWS\1.txt 2.txt
ren g:\WINDOWS\1.txt 2.txt
ren h:\WINDOWS\1.txt 2.txt

一直下去。。。。
回复

使用道具 举报

5#
发表于 2010-10-26 19:57:55 | 只看该作者
for %%c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
        if exist %%c:\windows\1.txt ren %%c:\windows\2.txt
                    )

[ 本帖最后由 haiou327 于 2010-10-26 19:59 编辑 ]
回复

使用道具 举报

6#
 楼主| 发表于 2010-10-26 20:18:43 | 只看该作者

回复 #5 haiou327 的帖子

还是不可以。。。运行如下。


D:\>12.bat

D:\>for %c in (c d e f g h i j k l m n o p q r s t u v w
\windows\1.txt ren %c:\windows\2.txt )

D:\>(if exist c:\windows\1.txt ren c:\windows\2.txt )

D:\>(if exist d:\windows\1.txt ren d:\windows\2.txt )
命令语法不正确。

D:\>(if exist e:\windows\1.txt ren e:\windows\2.txt )
命令语法不正确。

D:\>(if exist f:\windows\1.txt ren f:\windows\2.txt )

D:\>(if exist g:\windows\1.txt ren g:\windows\2.txt )

D:\>(if exist h:\windows\1.txt ren h:\windows\2.txt )

D:\>(if exist i:\windows\1.txt ren i:\windows\2.txt )

D:\>(if exist j:\windows\1.txt ren j:\windows\2.txt )

D:\>(if exist k:\windows\1.txt ren k:\windows\2.txt )

D:\>(if exist l:\windows\1.txt ren l:\windows\2.txt )

D:\>(if exist m:\windows\1.txt ren m:\windows\2.txt )

D:\>(if exist n:\windows\1.txt ren n:\windows\2.txt )

D:\>(if exist o:\windows\1.txt ren o:\windows\2.txt )

D:\>(if exist p:\windows\1.txt ren p:\windows\2.txt )

D:\>(if exist q:\windows\1.txt ren q:\windows\2.txt )

D:\>(if exist r:\windows\1.txt ren r:\windows\2.txt )

D:\>(if exist s:\windows\1.txt ren s:\windows\2.txt )

D:\>(if exist t:\windows\1.txt ren t:\windows\2.txt )

D:\>(if exist u:\windows\1.txt ren u:\windows\2.txt )

D:\>(if exist v:\windows\1.txt ren v:\windows\2.txt )

D:\>(if exist w:\windows\1.txt ren w:\windows\2.txt )

D:\>(if exist x:\windows\1.txt ren x:\windows\2.txt )

D:\>(if exist y:\windows\1.txt ren y:\windows\2.txt )

D:\>(if exist z:\windows\1.txt ren z:\windows\2.txt )
回复

使用道具 举报

7#
发表于 2010-10-26 20:36:41 | 只看该作者
和你说不清楚了,自己学习去吧。
运行 for /?   和 if /? 如果能明白在说。不然没有人能和你说清楚。
回复

使用道具 举报

8#
发表于 2010-10-26 20:41:36 | 只看该作者
明显是ren错了……
回复

使用道具 举报

9#
发表于 2010-10-26 20:56:01 | 只看该作者
for %%c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
        if exist %%c:\windows\1.txt ren %%c:\windows\1.txt 2.txt
                    )
回复

使用道具 举报

10#
发表于 2010-10-26 21:33:11 | 只看该作者
命令行下应该是:for %c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (if exist %c:\windows\1.txt ren %c:\windows\1.txt 2.txt)
批处理中才是楼上的写法。

[ 本帖最后由 zxw 于 2010-10-26 21:45 编辑 ]
回复

使用道具 举报

11#
发表于 2010-10-27 10:46:04 | 只看该作者
如果 1.txt 和 2.txt 同时存在的情况下,是无法把1.txt 更名成 2.txt 的。
回复

使用道具 举报

12#
 楼主| 发表于 2010-10-27 18:47:19 | 只看该作者

回复 #10 zxw 的帖子

谢谢!dos下运行正确!
原来是在windows下commad.exe运行的。。
回复

使用道具 举报

13#
 楼主| 发表于 2010-10-27 18:47:46 | 只看该作者

回复 #11 dos时代菜鸟 的帖子

嗯。谢谢。!
我很菜。。。dos命令
回复

使用道具 举报

14#
发表于 2010-10-27 23:29:14 | 只看该作者
for %%c in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
       if exist %%c:\WINDOWS\system32\1.exe ren %%c:\WINDOWS\system32\1.exe 1.exes
          if exist %%c:\WINDOWS\system32\drivers\2.sys ren %%c:\WINDOWS\system32\drivers\2.sys 2.syss
             )
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-4-19 21:39

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表