[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 批处理命令for /f移动、复制电脑桌面和我的文档中的文件为何不成功?

有时候下载的文件顺手放在电脑桌面上,闲暇时想通过批处理将其移动到制定的文件夹中,但做怎么也不成功,但是同样的批处理复制或移动桌面和我的文档以外的文件则没有任何问题。
beifen.bat:
  1. @echo on
  2. title 音频备份
  3. if not exist e:\笑笑课程\nul MD e:\笑笑备份
  4. if exist mp3.txt del mp3.txt>nul
  5. dir/s /b /a c:|findstr /i /e "mp3"|findstr /i "2012最火铃声">>mp3.txt
  6. for /f %%i in (mp3.txt) do xcopy /y /h "%%i" e:\笑笑备份
复制代码
-------------------------------------
MP3.txt:
C:\Documents and Settings\Administrator\桌面\2012最火铃声12首\2012最火铃声(10).mp3
C:\Documents and Settings\Administrator\桌面\2012最火铃声12首\2012最火铃声(11).mp3
C:\Documents and Settings\Administrator\桌面\2012最火铃声12首\2012最火铃声(12).mp3
C:\Documents and Settings\Administrator\桌面\2012最火铃声12首\2012最火铃声(1).mp3

--------------------------------------
运行结果如下:

F:\>dir/s /b /a c:  | findstr /i /e ".mp3"  | findstr /i "2012最火铃声12首" 1>>mp3.txt
F:\>for /F %i in (.\mp3.txt) do xcopy /y /h "%i" e:\笑笑备份

F:\>xcopy /y /h "C:\Documents" e:\笑笑备份
找不到文件 - Documents
复制了 0 个文件

F:\>xcopy /y /h "C:\Documents" e:\笑笑备份
找不到文件 - Documents
复制了 0 个文件

F:\>xcopy /y /h "C:\Documents" e:\笑笑备份
找不到文件 - Documents
复制了 0 个文件

以上的运行结果,显然是失败的,但是当mp3文件在C:\盘其它文件夹中或者d:\盘、e:\盘、f:\盘等任意位置,均可执行成功,请朋友们帮我看看是什么原因造成的?

  1. @echo on
  2. title 音频备份
  3. if not exist e:\笑笑课程\ (
  4.     md e:\笑笑备份
  5. )
  6. if exist mp3.txt (
  7.     del /f /q mp3.txt
  8. )
  9. dir /s /b /a-d /a c:|findstr /i "2012最火铃声.*\.mp3$" >mp3.txt
  10. for /f "delims=" %%i in (mp3.txt) do (
  11.     xcopy /y /h "%%i" e:\笑笑备份
  12. )
复制代码

TOP

  1. @echo on
  2. title 音频备份
  3. if not exist e:\笑笑课程\ (
  4.     md e:\笑笑备份
  5. )
  6. for /f "delims=" %%i in ('dir /s /b /a-d /a c:^|findstr /i "2012最火铃声.*\.mp3$"') do (
  7.     xcopy /y /h "%%i" e:\笑笑备份
  8. )
复制代码

TOP

非常感谢DAIC 朋友的帮助!!!

TOP

回复 2# DAIC
请教DAIC大大个问题
@echo on
title 音频备份
if not exist e:\笑笑课程\ (
    md e:\笑笑备份
)
if exist mp3.txt (
    del /f /q mp3.txt
)
dir /s /b /a-d /a c:|findstr /i "2012最火铃声.*\.mp3$" >mp3.txt
for /f "delims=" %%i in (mp3.txt) do (
    xcopy /y /h "%%i" e:\笑笑备份
)

$这个符号有什么用途,搜索了一下,没有找到相关解释。

TOP

TOP

回复 6# DAIC


    谢谢

TOP

返回列表