简体   繁体   English

xcopy在我的批处理文件中不起作用,我不确定为什么吗?

[英]xcopy isn't working in my batch file, and I am not sure why?

First time poster here! 第一次海报在这里! I usually lurk for answers but seeing as I've been getting a headache on this and I really want this done for my boss I wanted to directly ask and see if anyone can spot what is wrong with my script. 我通常会偷偷摸摸地寻找答案,但是看到我一直对此感到头疼时,我真的想为我的老板做到这一点,我想直接问一下,看看是否有人可以发现我的脚本出了什么问题。

    @echo off
    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value')do set "dt=%%a"
    set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
    set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

    set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
    set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

    set "new_name=PayCase_%fullstamp%"

    echo datestamp: "%datestamp%"
    echo timestamp: "%timestamp%"
    echo fullstamp: "%fullstamp%"

    move /-y "E:\RFT workspace folder\PayCase_Project_Playground_logs\PayCase_ScriptLog" "%~dp0\Log Archive\%new_name%"

    xcopy /e "%~dp0\Log Archive\%new_name%" "%~dp0\Log Archive\sendFolder"

    pause

    EXIT

This first part of the script just gets today's date and time and sets it to a var called 'new_name' (it's not my code, got it from somewhere, I forget where). 脚本的第一部分只是获取今天的日期和时间,并将其设置为一个名为“ new_name”的变量(这不是我的代码,是从某个地方获取的,我忘记了在哪里)。 The latter part, moves the contents of the folder from one place to another, then it is suppose to copy those contents to another place in the drive. 后一部分将文件夹的内容从一个位置移动到另一位置,然后假定将这些内容复制到驱动器中的另一位置。

Can someone help me figure out why my code is not copying the contents to my sendFolder? 有人可以帮我弄清楚为什么我的代码没有将内容复制到我的sendFolder吗?

The only thing I see is that you are not using all the switches. 我唯一看到的是您没有使用所有的开关。 Try it with switches /s . 尝试使用开关/s Second and most importantly you are using the %~dp0 WRONG! 其次,最重要的是,您正在使用%~dp0错误!

Type this in a txt file and save it as a batch file 在txt文件中键入此文件并将其另存为批处理文件

Echo %~dp0
Pause

Run it, you will already find a \\ at the last so for example you would have a path like this C:\\Wherever\\bat\\is\\ at the last there is already an \\ . 运行它,您将在最后找到一个\\ ,例如,您将拥有一个像C:\\Wherever\\bat\\is\\这样的路径,最后一个已经有一个\\

You have typed this "%~dp0\\Log Archive\\%new_name%" which would result in "C:\\Wherever\\bat\\is\\\\Log Archive\\%new_name%" . 您已键入此"%~dp0\\Log Archive\\%new_name%" ,这将导致"C:\\Wherever\\bat\\is\\\\Log Archive\\%new_name%"

See that? 看到了吗? A slight mistake can get the whole thing wrong. 轻微的错误可能会使整个事情出错。 So try adding the /s switch and editing your code like this 因此,尝试添加/ s开关并像这样编辑代码

xcopy /s /e "%~dp0Log Archive\\%new_name%" "%~dp0Log Archive\\sendFolder"

Please also follow @JosefZ Comment 也请关注@JosefZ评论

Regards, 问候,

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM