系统找不到指定的文件(随机发生)

时间:2016-01-27 23:45:58

标签: batch-file

我有一个批处理文件,我从FTP服务器下载文件。在此之前,它会根据日期/时间创建一个文件夹。如果没有要下载的文件,则删除该文件。但是它只删除90%(给予或接受)时间的文件。其他时候会抛出错误The system cannot find the file specified。我不确定是什么造成了差异或为什么偶尔它不起作用。如果有所不同,则批处理脚本正在Windows Server 2012 R2上运行。

ping ##.#.###.# -n 1 -w 1000
set FileName=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_%TIME:~0,2%-%TIME:~3,2%

if %errorlevel% EQU 1 (
    :: Create timestamp of failed ping
    echo "Unable to ping. Timestamp: %FileName%" > "Archive-FileTransferProd\%FileName%.txt"
) else (

    :: Create folder on server based on current datetime (24 hour)
    md %FileName%

    :: FTP Commands
    :: Logg in to FTP
    echo user %UserName%> ftpCmd.dat
    echo %Password%>> ftpCmd.dat
    echo prompt>> ftpCmd.dat

    :: Copy items to server
    echo lcd "%FileName%">> ftpCmd.dat
    echo mget *>> ftpCmd.dat

    :: Delete files on server
    ::echo mdel *>> ftpCmd.dat

    :: Disconnect and clean up connection
    echo disconnect>> ftpCmd.dat
    echo bye>> ftpCmd.dat
    ftp -n -s:ftpcmd.dat %Server%
    del ftpCmd.dat


    set cnt=0
    for %%A in ("%FileName%\*") do set /a cnt+=1

    echo File name = %FileName%
    echo Count is = %cnt%

    :: If the folder is empty delete it
    IF %cnt% EQU 0 (
    echo File Deleted?
        rd /S /Q "C:\FileTransfer\%FileName%"
    ) 

)

其他信息

我一直在查看命令提示符并找到以下内容。使用的代码没有为文件夹指定正确的名称。无论代码是md %FileName%还是md "%FileName%"

,都会发生这种情况

enter image description here

1 个答案:

答案 0 :(得分:0)

更改 “%FileName%”\ * to “%FILENAME%\ *”

也改变 rd /S /Q C:\FileTransfer\"%FileName%"rd /S /Q "C:\FileTransfer\%FileName%"