|
bsmqu
初级用户
 
积分 114
发帖 6
注册 2005-4-4
状态 离线
|
『楼 主』:
[求助]移走目录下除.td和.cfg后缀的文件
[求助]移走目录下除.td和.cfg后缀的文件
我知道要先找到除这两个后缀多外的文件名,但我不知道怎么做了
请各位指教,谢谢
|
|
2008-5-28 11:33 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第
2 楼』:
假设是从d:\test移到d:\temp
@echo off&setlocal enabledelayedexpansion
set str=.td .cfg
for /f "delims=" %%i in ('dir /s /a-d /b d:\test\*.*') do (
set "flag="
for %%a in (%str%) do if "%%a"=="%%~xi" set flag=A
if not defined flag move /y "%%i" d:\temp\
)
echo 搞定!
pause>nul
Last edited by zw19750516 on 2008-5-28 at 01:08 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-5-28 12:36 |
|
|
bsmqu
初级用户
 
积分 114
发帖 6
注册 2005-4-4
状态 离线
|
『第
3 楼』:
我没有别的,就只有说声谢谢了。
不过这个处理会将子目录下的文件也移走, 建议在dir /s /a-d /b时改为dir /a-d /s
|
|
2008-5-28 16:04 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第
4 楼』:
Originally posted by bsmqu at 2008-5-28 16:04:
我没有别的,就只有说声谢谢了。
不过这个处理会将子目录下的文件也移走, 建议在dir /s /a-d /b时改为dir /a-d /s
我以为楼主是要移走所有的,所以我加了/s,如不要移走子目录中的去掉/s就可以了。
Last edited by zw19750516 on 2008-5-28 at 04:23 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-5-28 16:17 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第
5 楼』:
Originally posted by zw19750516 at 2008-5-28 04:17 PM:
我以为楼主是要移走所有的,所以我加了/s,如不要移走子目录中的去掉/s就可以了。
Last edited by zw19750516 on 2008-5-28 at 04:23 PM ]
@echo off&setlocal enabledelayedexpansion
set str=.td .cfg
for /f "delims=" %%i in ('dir /a-d /b D:\batch\test\*.*') do (
set "flag="
for %%a in (%str%) do if "%%a"=="%%~xi" set flag=A
if not defined flag move /y "%%i" D:\batch\test\temp\
)
pause
为什么我运行这个会出错?错误信息是:
D:\batch>moveFile
The system cannot find the file specified.
The system cannot find the file specified.
Press any key to continue . . .
另外'dir /a-d /s也会出错:
D:\batch>moveFile
The system cannot find the file specified.
The system cannot find the file specified.
The filename, directory name, or volume label syntax is incorrect.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the file specified.
The filename, directory name, or volume label syntax is incorrect.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the file specified.
The filename, directory name, or volume label syntax is incorrect.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the file specified.
" Total Files Listed:" is not a recognized device.
" Total Files Listed:" is not a recognized device.
The filename, directory name, or volume label syntax is incorrect.
The system cannot find the file specified.
The system cannot find the file specified.
Press any key to continue . . .
给解析下,谢谢
|

無求一生光輝 唯朢鬥志不會斷 |
|
2008-5-28 16:46 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
|
2008-5-28 17:24 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第
7 楼』:
Originally posted by zw19750516 at 2008-5-28 05:24 PM:
D:\batch\test\temp\这个路径是不是实际存在的啊。
存在的呢。我运行
@echo off&setlocal enabledelayedexpansion
set str=.td .cfg
for /f "delims=" %%i in ('dir/b/a-d "D:\batch\test\*.*"') do (
set "flag="
for %%a in (%str%) do if "%%a"=="%%~xi" set flag=A
if not defined flag move /y "%%i" D:\batch\test\temp\
)
pause
是可以的!非常奇怪,去掉/s就不行了
-------------------------------------------------------------
另外,我测试
for /f "delims=" %%i in ('dir/b/a-d "D:\batch\test\*.*"') do (
echo %%~nxi
)
是能遍历test底下的文件的呢,很奇怪哦
|

無求一生光輝 唯朢鬥志不會斷 |
|
2008-5-28 17:31 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第
8 楼』:
搞错了,应该是运行
for /f "delims=" %%i in ('dir/b/a-d/s "D:\batch\test\*.*"') do (
set "flag="
for %%a in (%str%) do if "%%a"=="%%~xi" set flag=A
if not defined flag move /y "%%i" D:\batch\test\temp\
)
pause
是可以的
|

無求一生光輝 唯朢鬥志不會斷 |
|
2008-5-28 17:32 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第
9 楼』:
按理说,这个'dir/b/a-d "D:\batch\test\*.*"'指令是没有问题的啊!
现在情况是文件夹test底下有几个文件,它就显示几句
The system cannot find the file specified.
错误提示
很奇怪,什么原因呢,为什么说路径不对呢?
|

無求一生光輝 唯朢鬥志不會斷 |
|
2008-5-28 17:36 |
|