How to find out all files and their appropriate paths on drive using powershell?

Posted on 2009-12-18
Last Modified: 2013-11-10
Hi All,

Just need PS script which will display me all files and their paths in second column for example on some hard drive.
Lets say that I have "C:\" hard drive and i'm interesting to see all files with their paths.

I find out this code:

$Path = "d:\backups"
$a = get-Childitem $Path -recurse | format-table -group{$_.Path} name, directory -autosize

but it works only for backups folder, when I replace it to "d:\" it doesn't work I get message: WARNING: column "directory" does not fit into the display and was removed.

So folks, what I'm doing wrong?

Thanks for answer in advice.

Best Regards.
Question by:davidzak
    LVL 1

    Expert Comment

    Have your tried setting the path $Path="d:" without the backslash?

    Author Comment

    Yes, unfortunately same behavior...
    LVL 1

    Expert Comment

    I think the problem is generated becuase as it recurses down through the directories, the output for directory gets progressivly longer and ultimately will not fit in the display.  Perhaps adding wrap will help.  Try the following:

    $Path = "d:\"
    $a = get-Childitem $Path -recurse | format-table -group{$_.Path} name, directory -wrap -autosize
    LVL 1

    Accepted Solution

    I have test this syntax in both PS1.0 and 2.0 and it worked fine at three machines -

    $Path = "D:\"
    $a = get-Childitem $Path -recurse | format-table -group{$_.Path} name, directory -autosize

    Author Closing Comment

    I want to see this one: get-Childitem "c:\" -force -recurse | format-table -group{$_.Path} name, directory | out-file -width 250 "c:\foo.txt"
    LVL 1

    Expert Comment

    You may also try working with CSV file -

    get-Childitem "c:\" -force -recurse |Select-Object Name,FullName |Export-Csv "c:\foo.csv"

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    fix34  challenge 9 70
    seriesUp challenge 7 81
    copyEvens challenge 6 46
    Exe program is not a valid Win 32 application 15 74
    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now