Windows:如何建立有關目錄中檔案的資訊的製表符分隔列表

Windows:如何建立有關目錄中檔案的資訊的製表符分隔列表

作為一名 Linux 用戶,我不知道如何在 Windows 上解決以下問題(使用 cmd.exe):

我想遞歸地列出給定目錄中的所有文件,並將以下資訊以製表符分隔到文件中:

  1. 完整路徑
  2. 不含檔案名稱的完整路徑
  3. 檔案名稱
  4. 檔案後綴
  5. 上次更改的時間戳
  6. 最近接觸過該文件的用戶

例如

c:\folderA\file1.txt<tab>c:\folderA<tab>file1.txt<tab>txt<tab>2016-02-18 15:18:29 +0100<tab>USER_X

c:\folderA\file2.txt<tab>c:\folderA<tab>file2.txt<tab>txt<tab>2018-02-28 14:28:44 +0100<tab>USER_Y

c:\folderA\folderAA\file3.xlsx<tab>c:\folderA\folderAA<tab>file3.xlsx<tab>xslx<tab>2011-12-01 05:22:01 +0100<tab>USER_Z

可能存在名稱中帶有空格的檔案和資料夾。

有什麼建議麼?謝謝你!

答案1

使用電源外殼代替指令使用 powershell 命令Get-ChildItem別名GCI

完整命令:

gci -r | % { $_.Name,$_.FullName,$_.LastWriteTime -join ' ' } | Out-File YourOutputfile.txt

gci 取得子項目

-r 遞迴的

$_.Name 檔案名稱

$_.FullName 文件完整路徑

相同的輸出:

Get-ChildItem -r | % { $_.Name,$_.FullName,$_.LastWriteTime -join ' ' } | Out-File YourOutputfile.txt

如果您仍然想使用cmd,請輸入for /?按 Enter 並閱讀本節


    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:

    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line

相關內容