根据文件夹中的文件创建变量

每个星期五晚上文件将被放置在一个目录中。我正在编写一个批处理文件来归档文件(使用简单的复制命令),然后我需要重命名并将文件加载到OLAP数据库中。不幸的是,我不知道每周的文件名是什么,因为它是基于日期和时间戳的 - 我知道的唯一的事情就是将以.txt结束。根据文件夹中的文件创建变量

由于这将是该文件夹中唯一的文件,是否有可能创建一个基于文件名的变量?

这是我到目前为止有:

if not exist "%LoadFolder%\*.txt" (

rem Send email notification that the latest Exchange Rates file does not exist...

"E:\Programs\PuTTY\plink.exe" -v -ssh servername -pw password /u02/hyp_app/Scripts/STFC/STFC_File_Not_Exist.ksh

exit

) else (

rem 1) Copy latest file to Archive folder...

FOR /F "delims=|" %%I IN ('DIR "%LoadFolder%\*.txt" /B /O:D') DO SET NewestFile=%%I

copy "%Load%\%NewestFile%" "%LoadFolder%\Archive\%NewestFile%"

rem 2) Rename the latest file to Load_File.txt...

FOR /F "delims=|" %%I IN ('DIR "%LoadFolder%\*.txt" /B /O:D') DO SET NewestFile=%%I

REN "%LoadFolder%\%NewestFile%" "Load_File.txt"

)

REM rest of code..........

我的问题是,该文件夹重命名为LOAD_FILE而不是在文件夹中的文件。我究竟做错了什么?

回答:

假设存档文件夹存在,请尝试此脚本并发布确切的错误(如果有的话)。在SS64 CMD给

@echo off 

setlocal enabledelayedexpansion

set LoadFolder=yourFolderPath

if not exist "%LoadFolder%\*.txt" (

rem Send email notification that the latest Exchange Rates file does not exist...

"E:\Programs\PuTTY\plink.exe" -v -ssh servername -pw password /u02/hyp_app/Scripts/STFC/STFC_File_Not_Exist.ksh

) else (rem Copy latest file to Archive folder and rename it at source dir

FOR %%I IN ("%LoadFolder%\*.txt") DO (

copy %%I "%LoadFolder%\Archive\%%~nxI"

ren %%I Load_File%%~xI))

timeout 5

exit /b

了解更多关于path modifiers:你真正的文件夹路径替换yourFolderPath

以上是 根据文件夹中的文件创建变量 的全部内容, 来源链接: utcz.com/qa/259164.html

回到顶部