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

时间:2016-08-01 21:11:47

标签: variables batch-file

每个星期五晚上,文件将被放置在目录中。我正在编写一个批处理文件来存档文件(使用简单的复制命令),然后我需要重命名并将文件加载到OLAP数据库中。不幸的是,我不知道每周的文件名是什么,因为它是基于日期和时间戳 - 我唯一知道的是它将以╔═════╦══════════╦════╦════╦ ║ FO ║ group ║ ║ ╠═════╬══════════╬═════════╬ ║ 1 ║ 1 ║ ║ ║ 2 ║ 1 ║ ║ ║ 3 ║ 1 ║ ║ ║ 4 ║ 2 ║ ║ ║ 5 ║ 2 ║ ║ ║ 6 ║ 2 ║ ║ ╚═════╩══════════╩════╩════╩ 结束。

由于这将是文件夹中唯一的文件,是否可以根据文件名创建变量?

这是我到目前为止所得到的:

.txt

我遇到的问题是该文件夹正在重命名为Load_File而不是文件夹中的文件。我做错了什么?

1 个答案:

答案 0 :(得分:0)

假设存在存档文件夹,请尝试此脚本并发布确切错误(如果有)。将 yourFolderPath 替换为您的真实文件夹路径:

@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

SS64 Cmd参考中的path modifiers上阅读更多内容。