列出具有 2 个时间戳、大小但没有路径或目录的所有文件

List all files with 2 timestamps, size, but without path or dir

Windows,命令提示符,需要生成一个 .txt 文件输出,其中包含来自大型复杂目录树的所有文件,每个文件一 (1) 行,如:

创建日期YYYYMMDD-HHMMSS,最后修改时间YYYYMMDD-HHMMSS,文件大小[无 K 逗号],filename.ext

例如:

20100101-174503, 20120202-191536, 1589567, myfile.ext

该列表不应包含目录名称条目等行,而应仅包含文件名,即使同一个文件出现不止一次。 24 小时格式的时间。

dir /s/t:c/t:w/-c > filelist.txt

命令并不是这样工作的。

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=c:\program files"
FOR /f "delims=" %%a IN (
  'dir /s /b /a-d "%sourcedir%\*" '
  ) DO (
  FOR %%d IN (timewritten timecreated) DO SET "%%d="
  FOR %%k IN (-d s h) DO (
   IF NOT DEFINED timewritten FOR /f "tokens=1,2 delims= " %%d IN ('dir /tw %%~k "%%a" 2^>nul ^|find "%%~nxa"') DO SET "timewritten=%%d %%e"
   IF NOT DEFINED timecreated FOR /f "tokens=1,2 delims= " %%d IN ('dir /tc %%~k "%%a" 2^>nul ^|find "%%~nxa"') DO SET "timecreated=%%d %%e"
  )
  ECHO !timecreated! !timewritten! %%~za %%~nxa
  )
)
GOTO :EOF

您需要更改 sourcedir 的设置以适合您的情况。

有趣的问题。此代码通过

处理它

首先,将树上文件名的标准目录列表从相对根 (%sourcedir%) 应用到 %%a

使用 %%a 中的完整文件名,从针对相关文件的普通 dir 列表中设置 timewrittentimecreated

似乎 %%~ta 不能很好地提取隐藏文件和系统文件的时间戳,所以我决定从普通的 dir 列表中构建它们,并使用适当的 t 设置,特别是用 /a-d、/as 和 /ah 列出并过滤与文件名匹配的行,这似乎适当地提取了数据。

我以原始格式保留了 date/time。提取各种元素并以您想要的格式构建报告应该是一件容易的事。

这个问题是 SO post cmd dir /b/s plus date 的骗局,但是 post 对我有用:

@echo off
REM list files with timestamp
REM Filename first then timestamp
for /R %I in (*.*) do @echo %~dpnxI %~tI

@echo off
REM list files with timestamp
REM Timestamp first then name
for /R %I in (*.*) do @echo %~tI %~dpnxI

以上是您可以直接粘贴到命令提示符中的版本。 如果你想在批处理文件中使用这些并记录输出,你可以这样做:

rem: Place the following in a batch file such as DirectoriesBareWithTS.cmd.
rem: As the first step in the batch file, net use to the directory or share you want the listing of
rem: Change to your target directory 
Y:
for /R %%I in (*.mp4) do @echo %%~tI %%~dpnxI 

然后您可以在执行时将输出通过管道传输到日志文件:

DirectoriesBareWithTS.cmd > C:\temp\GiantLongDirListing.log

然后您可以将该日志导入 Excel。