Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用名为.bat的变量打开文件,该变量仅为最近创建的变量_Batch File_Csv - Fatal编程技术网

Batch file 使用名为.bat的变量打开文件,该变量仅为最近创建的变量

Batch file 使用名为.bat的变量打开文件,该变量仅为最近创建的变量,batch-file,csv,Batch File,Csv,我想在我的“my Docs”目录中打开最新的.csv文件,该文件的文件名带有一个变量,因此:“E:\my Documents\name 20140731.csv”。这将在excel中打开 名称将始终保持不变,但最后一个数字将始终不同(20140731、20140814等) 我在同一个bat中打开了许多其他文件 start "" Chrome --profile-directory="Profile 1" "https://mail.google.com/" "https://stackove

我想在我的“my Docs”目录中打开最新的.csv文件,该文件的文件名带有一个变量,因此:
“E:\my Documents\name 20140731.csv”
。这将在excel中打开

名称将始终保持不变,但最后一个数字将始终不同(20140731、20140814等)

我在同一个bat中打开了许多其他文件

start "" Chrome --profile-directory="Profile 1" "https://mail.google.com/"   "https://stackoverflow.com/users/2337102/mrsadmin"
start "" Excel "E:\My Business\master.xlsm"
start "" Excel "E:\My Business\test.xlsm"
start "" Excel "E:\My Business\reconciled 20131031.xlsx"
start "" Excel "E:\My Documents\dev.xlsx"
start "" Explorer "E:\My Business\Accounts"
start "" "D:\Programs\2 Admin\MySQL Workbench\MySQLWorkbench.exe"
start "" Notepad "E:\My Business\info.txt
我已尝试添加(来自):

但是,这不起作用,我会收到关于文件不存在的错误消息

非常感谢

for /f "delims=" %%a in (
    'dir /b /a-d /od "E:\My Documents\name*.csv"'
) do set "RecentFile=%%~a"

start "" "E:\My Documents\%RecentFile%"
由于文件包含空格,因此/f的
标记字符串并返回第一个标记,即字符串
名称
。禁用分隔符(将delims设置为空列表)可以避免此操作

for /f "delims=" %%a in (
    'dir /b /a-d /od "E:\My Documents\name*.csv"'
) do set "RecentFile=%%~a"

start "" "E:\My Documents\%RecentFile%"