简体   繁体   English

如何将名为文件的变量从一个目录移动到另一个目录?

[英]How do I move variable named files from one directory to another?

Here is what I have so far that doesn't work: 这是我到目前为止无法正常工作的内容:

set from=V:\directory\CONCA*.*
set to=V:\directory\CONCA
for /f %%a IN ('dir "%from%" /b') do move %from%\%%a %to%

This returns the error message: 这将返回错误消息:

The filename, directory name, or volume label syntax is incorrect 文件名,目录名称或卷标签语法不正确

I do not always have a file in the directory that it is from, I do not want to see any error messages when it does not find a file. 我并不总是在它来自的目录中有一个文件,当它找不到文件时,我不想看到任何错误消息。

I do want to see what is it moving when it finds something to move. 我确实想看看当它找到要移动的东西时它在移动什么。

set "from=V:\directory"
set "to=V:\directory\CONCA"
    rem ensure that target folder exists
md "%to%" 2>NUL
for /f "delims=" %%a IN ('dir "%from%\CONCA*.*" /b /A:-D 2^>NUL') do (
    echo "%from%\%%a"
    rem move "%from%\%%a" "%to%\"
)

Explanation: 说明:

  • my comment to your question shows up the quoted error message culprit; 我对您的问题的评论显示出所引用的错误消息元凶;
  • 2>NUL redirect error messages to NUL ; 2>NUL 将错误消息重定向到NUL we need to escape > redirection operator when used in a command processed by for /F loop as 2^>NUL ; 当在for /F循环处理为2^>NUL的命令中使用时,我们需要转义 >重定向运算符;
  • "delims=" to treat possible spaces in file names properly; "delims="以正确处理文件名中的可能空格;
  • /A:-D exclude folders to prevent move "V:\\directory\\CONCA" "V:\\directory\\CONCA\\" (attempt to move itself to itself ); /A:-D排除文件夹以防止move "V:\\directory\\CONCA" "V:\\directory\\CONCA\\" (尝试将自身移动到自身 );
  • echo "%from%\\%%a" to satisfy I do want to see what is it moving when it finds something to move claim; echo "%from%\\%%a"以满足我确实想查看它发现要移动的内容时发生了什么变化
  • rem move "%from%\\%%a" "%to%\\" operational move command is commented up using rem merely for debugging phase: remove rem as soon as debugged (but no sooner). rem move "%from%\\%%a" "%to%\\"操作性move命令仅在调试阶段使用rem进行了注释:在调试后立即删除rem (但不要尽快删除)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文件从一个目录移动到另一个目录,但每次只移动一个文件 - How to move files from one directory to another but only move a file each time 将列表中的文件从FTP服务器上的一个目录移动到另一个目录 - Move files in a list from one directory to another on FTP server 如何根据文件大小将文件从目录移动到另一个目录 - How to move files from a directory to another directory based on file size 如何将一个目录树的内容移动到另一个目录树中? - How can I move the contents of one directory tree into another? 用于从文本文件列表(Windows)将文件从一个目录移动到另一个目录的批处理脚本 - Batch script for move files from one directory to another from list of text files (windows) 如何将4个最新文件从受密码保护的在线目录复制到另一个目录? - How do I copy the 4 latest files from a password-protected online directory to another directory? 将文件夹内容从一个目录移动到另一个目录 - Move folder content from one directory to another 将文件移到一个目录 - move files to one directory 如何使用命令行将所有文件从一个文件夹移动到另一个文件夹? - How can I move all the files from one folder to another using the command line? 如何编写将一个目录复制到另一个目录的批处理脚本,替换旧文件? - How do I write a batch script that copies one directory to another, replaces old files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM