XCOPY未被识别为内部或外部命令

时间:2016-01-27 12:04:02

标签: windows batch-file

我对批处理文件编码很新。我试图使用XCOPY复制一些文件。首先,我这样使用:

   <?php

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'admin');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_POST["register"]))
{
    $id = $_POST["id"];
    $name = $_POST["user_name"];
   $password = $_POST["password"];
    $result = mysqli_query($db, "INSERT INTO user (id, user_name, password)VALUES ('$id', '$name', '$password')");


 if($result)
{
    echo "<script>alert('User Register Successfully Go to login!')</script>";
    echo "<script>window.open('index.php','_self')</script>";
}
}
?>

此代码工作正常。 然后我需要从用户那里获得一些输入,o我修改了这样的代码:

@echo off

MOVE mypath\abc.txt mypath\abc.txt.0001
XCOPY mypath\abc.txt.bak mypath\abc.txt

pause

此代码未运行。它说:

@ECHO off

ECHO Starting application.
SET /p path=Enter the path: 
SET /p corruptFileName=Enter the corrupted file name: 
SET /p oldBackupFileName=Enter the Backup file name to restore: 
SET /p correuptedBackupName=Enter the corrupted backup file name: 

ECHO Path : 
ECHO %path%
ECHO Corrupted file name : 
ECHO %corruptFileName%
ECHO Desired Backup file name:
ECHO %correuptedBackupName%
ECHO Backup file name to restore : 
ECHO %oldBackupFileName%


MOVE %path%\%corruptFileName% %path%\%correuptedBackupName%
call :waitfor 5000>nul
XCOPY %path%\%oldBackupFileName% %path%\%corruptFileName%

PAUSE

有人可以解释这个吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

%path%是一个环境变量,用于告诉操作系统程序所在的位置。没有它,您必须提供系统可执行文件的完整路径(如xcopy),然后才能按名称调用它们。

永远不要覆盖它。

将变量名称更改为其他名称。别的什么。