XCOPY还在问(F =文件,D =目录)确认 [英] XCOPY still asking (F = file, D = directory) confirmation

查看:2236
本文介绍了XCOPY还在问(F =文件,D =目录)确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的批处理脚本 XCOPY 仍要求 F =文件,D =目录确认,即使我加入 /˚F在脚本中,记录它是如下显示。
请上的是如何避免要求确认帮助。

脚本:

 净使用号码:/删除
NET USE号码:\\\\ 200clan \\ F_Drive/ USER:ADM / PERSISTENT:NO-1111
集源=%1
设定的目标= P:/ 2%回声%源%%的目标%XCOPY / S / I / Q / Y / F%源%%的目标%

日志:


  C:\\测试\\ foldera> XCOPY / S / I / Q / Y / FC:/test/folder1/folder2/logs/154/compareReport_177.htmlP :/Services/WSDLCompare/177_20151116/compareReport_177.html
难道病人:\\ SERVICES \\ WSDLCompare \\ 177_20151116 \\ UIReport_177.html指定文件名
上的目标或目录名
(F =文件,D =目录)?



解决方案

/ I 开关(未 /˚F正如你在你的问题中提到)prevents XCOPY 从询问目的地是一个文件或目录只有当多个源文件中给出,因此,如果源一个目录,或通配符 * 被使用。如果目标已经存在,如不及时永远不会出现。

有下列情况下(视%源%所提供的值%的目标%):


  • 一个源文件,目的地是一个文件:

    / I 开关是没用的,所以你需要管˚F XCOPY 命令行:

     呼应F | XCOPY / S / Q / Y / F%源%%的目标%


  • 一个源文件,目标是一个目录:

    / I 开关也没用太多;可以通过管道 D XCOPY 命令行:

     呼应开发| XCOPY / S / Q / Y / F%源%%的目标%

    或者你可以简单地追加一个 \\ 来的目的:

      XCOPY / S / Q / Y / F%源%%的目标%\\

    虽然这会导致麻烦时,%的目标%指定驱动器的像 D当前目录:例如,因为 D:表示该驱动器,而 D的当前目录:\\ 意味着它的根目录;


  • 多个源文件,目的地是一个文件:

    这是一个毫无意义的情况,因为你告诉 XCOPY 复制每个源文件相同的目标文件,从而企图覆盖它;


  • 多个源文件,目标是一个目录:

    / I 开关是有道理的位置:

      XCOPY / S / I / Q / Y / F%源%%的目标%

    管选项还会在这里工作:

     呼应开发| XCOPY / S / Q / Y / F%源%%的目标%

    也是如此追加 \\ 目的地(关于上述的限制):

      XCOPY / S / Q / Y / F%源%%的目标%\\


结论

最灵活和最安全的解决方案是将管道所需的选择(˚F D )到 XCOPY 命令行。 (注意查询语言环境相关。)


补充

有在code片段一些小问题,我想在这里提到:


  • 您通常应该使用 \\ 的,因为这是为这一目的的Windows标准字符(路径分隔符尽管 / 也工作在大多数情况下);

  • -1111 添加到您的第二个 NET USE 命令行;如果这构成了资源的密码,就应该在 / USER 选项之前移动;否则只是将其删除;

  • 设置命令行介绍一些特殊字符的问题(如&安培; ^ );为了避免这样的,国家设置源=%〜1设置目标= P:/%〜2;在消除潜在的周围的从参数(如果它们包含<大骨节病> SPACE ; = );

下面是code与所有的修改了上面的东西:

 净使用病人:/ DELETE
REM假设`-1111`构成了资源的密码:
NET USE病人:\\\\ 200clan \\ F_Drive-1111 / USER:ADM / PERSISTENT:NO设置源=%〜1
一套目标= P:\\%〜2回声%源%%的目标%REM假定目标是一个目录:
回声开发| XCOPY / S / I / Q / Y / F%源%%的目标%
REM其实你不需要任何临时变量:
REM回声开发| XCOPY / S / I / Q / Y / F%〜1P:\\%〜2

My batch script xcopy is still asking F = file, D = directory confirmation even though I added /F in the script, log it is showing as below. Please help on the is how to avoid to asking confirmation.

Script:

net use p: /delete  
net use p: "\\200clan\F_Drive" /USER:adm /PERSISTENT:NO-1111
set source=%1
set target=p:/%2

echo %source% %target%

xcopy /S /I /Q /Y /F "%source%" "%target%"

Log:

C:\test\foldera>xcopy /S /I /Q /Y /F "C:/test/folder1/folder2/logs/154/compareReport_177.html" "p:/Services/WSDLCompare/177_20151116/compareReport_177.html"
Does P:\Services\WSDLCompare\177_20151116\UIReport_177.html specify a file name
or directory name on the target
(F = file, D = directory)? 

解决方案

The /I switch (not /F as you mentioned in your question) prevents xcopy from asking whether the destination is a file or a directory only if multiple source files are given, so if the source is a directory, or if wildcards ? or * are used. If the destination already exists, such prompt does never appear.

There are the following scenarios (depending on the provided values of %source% and %target%):

  • a single source file, the destination is a file:

    the /I switch is useless, so you need to pipe F into the xcopy command line:

    echo F|xcopy /S /Q /Y /F "%source%" "%target%"
    

  • a single source file, the destination is a directory:

    the /I switch is useless too; you can pipe D into the xcopy command line:

    echo D|xcopy /S /Q /Y /F "%source%" "%target%"
    

    or you can simply append a \ to the destination:

    xcopy /S /Q /Y /F "%source%" "%target%\"
    

    although this causes trouble when %target% specifies the current directory of a drive like D: for instance, because D: means the current directory of this drive whereas D:\ means the root directory of it;

  • multiple source files, the destination is a file:

    this is a senseless situation, because you tell xcopy to copy each source file to the same destination file, thus attempting to overwrite it;

  • multiple source files, the destination is a directory:

    the /I switch makes sense here:

    xcopy /S /I /Q /Y /F "%source%" "%target%"
    

    the pipe option also works here:

    echo D|xcopy /S /Q /Y /F "%source%" "%target%"
    

    so does appending a \ to the destination (regarding the limitation as mentioned above):

    xcopy /S /Q /Y /F "%source%" "%target%\"
    

Conclusion

The most flexible and secure solution is to pipe the desired selection (F or D) into the xcopy command line. (Note that the query is locale-dependent.)


Supplement

There are some minor issues in your code fragment I want to mention here:

  • you should generally use the \ as a path separator as this is the Windows standard character for that purpose (although / works too in most cases);
  • there is -1111 appended to your second net use command line; if this constitutes the password for the resource, it should be moved before the /USER option; otherwise just remove it;
  • your set command lines introduce problems with some special characters (like &, ^, (, )); to avoid such, state set "source=%~1" and set "target=p:/%~2"; the ~ removes potential surrounding "" from the arguments (which are required if they contain SPACE, ,, ;, =);

Here is the code with the all of the above things reworked:

net use P: /DELETE
rem supposing `-1111` constitutes the password for the resource:
net use P: "\\200clan\F_Drive" -1111 /USER:adm /PERSISTENT:NO

set "source=%~1"
set "target=P:\%~2"

echo "%source%" "%target%"

rem supposing the destination is a directory:
echo D|xcopy /S /I /Q /Y /F "%source%" "%target%"


rem actually you do not need any interim variables:
REM echo D|xcopy /S /I /Q /Y /F "%~1" "P:\%~2"

这篇关于XCOPY还在问(F =文件,D =目录)确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆