我正在尝试通过网络使用批处理文件获取最后修改的数据
我用来获取信息的代码行是
wmic datafile where name="%file:\=\\%" get lastmodified
这适用于本地文件,但当我尝试在No Instance(s) Available
等网络文件上使用该行时出现\\networkshare\folder\file.txt
错误。
答案 0 :(得分:2)
datafile
不支持UNC路径。
您有两个选择
set "file=e:\somewhere\file.txt" wmic /node:serverName datafile where name="%file:\=\\%" get lastmodified
示例代码
@echo off
setlocal enableextensions disabledelayedexpansion
rem Configure file
set "file=\\server\share\folder\file.txt"
rem Separate path and filename
for %%a in ("%file%") do ( set "filePath=%%~dpa" & set "fileName=%%~nxa" )
rem Change to target path and adapt file path if sucessful
pushd "%filePath%" && (for %%a in (.\) do set "filePath=%%~fa")||(set "filePath=")
rem If the current directory has changed, get file data and return to previous folder
if defined filePath (
wmic datafile where "name='%filePath:\=\\%%fileName%'" get LastModified
popd
)