Board logo

标题: [文件操作] 批处理怎样对同一个文件夹来回改名? [打印本页]

作者: hanruiqi    时间: 2011-5-5 19:12     标题: 批处理怎样对同一个文件夹来回改名?

d盘里有一个文件夹 名称是 小狗

现在写一个批处理,要求是:

如果文件夹名称 是 小狗 就改成 小猫,如果是 小猫 就改成 小狗

如果属性是隐藏就改成显示,如果是显示就改成隐藏。

应该怎么写??

要求批处理文件放在任何一个地方都可以。
作者: lxzzr    时间: 2011-5-5 19:31

这贴http://www.bathome.net/thread-12208-1-1.html有什么问题???
作者: hfg1977    时间: 2011-5-5 20:21

虽然这个问题有够无聊, 我还是写了
  1. @echo off
  2. setlocal enabledelayedexpansion&cls
  3. if exist g:\1\ (
  4. call:get_attrib g:\1 & move g:\1 g:\2
  5. echo +!f-A_BL!+
  6. if !f-A_BL!==0 attrib +h g:\2
  7. ) else (
  8. if exist g:\2\ (
  9. call:get_attrib g:\2 & move g:\2 g:\1
  10. if !f-A_BL!==0 attrib +h g:\1)
  11. )
  12. :end
  13. exit/b
  14. :get_attrib
  15. set f_A=%~a1
  16. set f_A=%f_A:~3,1%
  17. echo "%f_A%"
  18. if "%f_A%"=="h" (set f-A_BL=1) else (set f-A_BL=0)
  19. attrib -h -r -s %~1
  20. goto:eof
复制代码

作者: 冷玉公子    时间: 2011-5-5 20:31

你的问题很简单
第一步取得文件夹的名称 用什么办法都可以
第二步判断文件夹名称 然后执行动作
第一步你没有说文件夹的具体位置信息 所以没有办法给你写
我直接写如果判断吧
  1. @echo off
  2. Set Var=小猫
  3. if "%Var%" == "小猫" Ren 小猫 小狗
  4. if "%Var%" == "小狗" Ren 小狗 小猫
复制代码
这里我就是意思一下 具体怎么拿文件夹名称 你得把具体信息发上来

文件夹的位置是不是固定的 而且这个目录里面是不是只有那一个文件夹
作者: CrLf    时间: 2011-5-5 22:04

隐藏文件是无法直接改名的
作者: yjstone    时间: 2011-5-5 22:08

本帖最后由 yjstone 于 2011-5-6 16:28 编辑

如果你的文件夹在D盘的根目录就试试如下这个吧:
  1. @echo off
  2. cd /d D:\
  3. if exist "小狗" (set "dirname=小狗") else set "dirname=小猫"
  4. dir "%dirname%">nul 2>nul&&set "hide=+"||set "hide=-"
  5. attrib -h -s %dirname%
  6. ren "小狗" "小猫"&&attrib %hide%h "小猫"||ren "小猫" "小狗"&attrib %hide%h "小狗"
复制代码
批处理放在哪运行都可以。
作者: CrLf    时间: 2011-5-5 22:22

另类思路
  1. @echo off
  2. set 1.txt=2.txt
  3. set 2.txt=1.txt
  4. if exist 1.txt set g=!
  5. setlocal enabledelayedexpansion
  6. dir>nul 2>nul /ah /b "%g%2.txt%g%"&&set "attrib=-h"||set "attrib=+h"
  7. attrib -h -s %g%2.txt%g%
  8. ren "%g%2.txt%g%" "%g%1.txt%g%"
  9. attrib %attrib% "%g%1.txt%g%"
  10. pause
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2