0

很抱歉标题很长,我想知道是否有人可以帮助我解决这个问题。

我要做的是读取一个包含 10 个不同目录路径的文件,获取该目录中的最新文件并读取该文件的最后一行。

@echo off
setlocal enableextensions enabledelayedexpansion
set host=%COMPUTERNAME%
echo Host: %host%
for /f "tokens=* delims=" %%I in (C:\temp\servers.txt) do (
    SET /A vidx=!vidx! + 1
    set var!vidx!=%%I
    echo Path-to-File: %%I
    for /f "tokens=* delims=" %%X in ('dir "%%I" /OD /B')  do (
    set newest=%%X
    )
    echo %newest%
    )

这是输出:

Host: Windows7
Path-to-File: \\Windows7\C$\direct\log\direct
ECHO is off.
Path-to-File: \\Windows7\C$\temp
ECHO is off.

在此先感谢您的帮助。

4

1 回答 1

0

对不起,我对你的描述有些困惑。下面的批处理文件是根据我了解您的要求编写的。

@echo off
setlocal EnableDelayedExpansion
echo Host: %COMPUTERNAME%

rem Process the file with the paths:
for /F "delims=" %%I in (C:\temp\servers.txt) do (
   echo Path-to-File: %%I
   rem Get the newest file in this directory
   for /F "delims=" %%X in ('dir "%%I" /OD /B') do (
      set "newest=%%~X"
   )
   echo Newest-File: !newest!
   rem Read the last line from this file
   for /F "usebackq delims=" %%L in ("!newest!") do (
      set "lastLine=%%L"
   )
   echo Last-Line: !lastLine!
)

我希望它有帮助...

安东尼奥

于 2013-02-07T21:03:05.673 回答