0

As a Linux user I have no idea to solve the following problem on Windows (using cmd.exe):

I want to list all files in a given directory recursively with the following information seperated by tabs into a file:

  1. full path
  2. full path w/o file name
  3. file name
  4. file suffix
  5. timestamp of last change
  6. user that touched the file recently

e.g.

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

There might be files and folders with spaces in their names.

Any suggestions? Thank you!

3
0

use powershell instead of cmd use powershell command Get-ChildItem alias GCI

Full Command:

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

gci Get-ChildItem

-r recursive

$_.Name File Name

$_.FullName File Full Path

same output:

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

If You still want to use cmd then type for /? hit enter and read this section


    %~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
1
  • Thanks @Sadam! What about the file's owner (or user that touched the file recently)?
    – dr.keule
    Mar 15 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.