locked
Generate list of files /Items in a folder RRS feed

  • Question

  • Hi,

    I have a folder lets say Root. This root folder may have several folders and files.

    My target is to generate list of all items in this Root folder that list the all folders and items in that subsequent folders (showing path 

    The output may be an HTML table with item number, physical path etc.

    Is it possible?


    N.A.Malik

    Monday, March 24, 2014 8:17 PM

Answers

  • Rather I was just trying to give a detailed or easy to understand way to Scripting professionals what I want to do. That's true, I am not learning PowerShell script since this is not my area of interest and I CAN NOT hire a scripting pro to write a line of sentence for me in couple of years.

    It seems you have an unrealistic expectation that you can post a script specification and others will write the code for you. It is like you are saying: "I don't have time to learn scripting, but I want you guys to translate my request into code for me for free, because my time is more valuable than yours."

    To clarify: The purpose of this forum is to answer scripting questions, not write code for others to spec. Remember, the help here is free, and we're volunteers.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Monday, May 19, 2014 10:11 PM
    Wednesday, March 26, 2014 2:22 PM

All replies

  • Hi,

    Yes, pretty much anything is possible with enough tweaking.

    Here's a start:

    Get-ChildItem .\Root -Recurse | 
        Select * |
            ConvertTo-Html |
                Out-File .\details.htm


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    • Proposed as answer by Peter Ziganki Tuesday, March 25, 2014 9:00 AM
    Monday, March 24, 2014 8:25 PM
  • This will get you started:

    Get-ChildItem c;\root -recurse |format-table -auto | Out-File files.txt


    ¯\_(ツ)_/¯

    Monday, March 24, 2014 8:26 PM
  • Numbers?

    $i=1;Get-ChildItem  -rec -File |%{'{0,8}    {1}' -f $i++,$_.Fullname} |ConvertTo-Html


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, March 24, 2014 9:01 PM
    Monday, March 24, 2014 9:01 PM
  • Hi,

    Yes, pretty much anything is possible with enough tweaking.

    Here's a start:

    Get-ChildItem .\Root -Recurse | 
        Select * |
            ConvertTo-Html |
                Out-File .\details.htm


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Hi,

    I tried this one, and it does created a file but that was empty.
    Output from the PowerShell ISE shows the following:

    + CategoryInfo          : PermissionDenied:
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>HTML TABLE</title>
    </head><body>
    <table>
    </table>
    </body></html>

    PS D:\>


    N.A.Malik

    Tuesday, March 25, 2014 9:54 AM
  • This will get you started:

    Get-ChildItem c;\root -recurse |format-table -auto | Out-File files.txt


    ¯\_(ツ)_/¯

    Hi,

    I checked it out, and receives the following:

    PS D:\WSP> D:\WSP\Getfile.ps1
    Get-ChildItem : Cannot find path 'D:\WSP\d' because it does not exist.
    At D:\WSP\Getfile.ps1:1 char:1
    + Get-ChildItem d;\WSP -recurse |format-table -auto | Out-File files.txt
    + ~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (D:\WSP\d:String) [Get-ChildItem], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
     
    \WSP : The term '\WSP' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
    path is correct and try again.
    At D:\WSP\Getfile.ps1:1 char:17
    + Get-ChildItem d;\WSP -recurse |format-table -auto | Out-File files.txt
    +                 ~~~~
        + CategoryInfo          : ObjectNotFound: (\WSP:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
     

    PS D:\WSP>


    N.A.Malik

    Tuesday, March 25, 2014 9:59 AM
  • Hi Malik,

    looks like the user you were running this command with didn't have the permissions to read the specified directory. That would cause the Get-ChildItem command to throw an error and return $null, which would lead to an empty table. Which is what you got.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, March 25, 2014 10:05 AM
  • Hi Malik,

    for your second post: You misspelled a command, placing a ";" where a ":" ought to go.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, March 25, 2014 10:17 AM
  • Hi Malik,

    looks like the user you were running this command with didn't have the permissions to read the specified directory. That would cause the Get-ChildItem command to throw an error and return $null, which would lead to an empty table. Which is what you got.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Hi,

    Its default Administrator user.


    N.A.Malik

    Tuesday, March 25, 2014 10:44 AM
  • Hi Malik,

    for your second post: You misspelled a command, placing a ";" where a ":" ought to go.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    You are correct, I have changed it to : and it worked.

    But output file format is not user friendly, its a kind of messy. can we make a easy to read table?


    N.A.Malik

    Tuesday, March 25, 2014 10:48 AM
  • yes, it can be formatted. Simple content changes are easy:

    Get-ChildItem c:\root -recurse | Select * | ConvertTo-Html | Out-File files.html

    If you only want some of the values, replace the "*" with the column header names (in the order you want them).

    More complex html reformatting will take some effort though.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Tuesday, March 25, 2014 10:58 AM
  • yes, it can be formatted. Simple content changes are easy:

    Get-ChildItem c:\root -recurse | Select * | ConvertTo-Html | Out-File files.html

    If you only want some of the values, replace the "*" with the column header names (in the order you want them).

    More complex html reformatting will take some effort though.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Hi,

    Thanks for the reply. I appreciate your help.

    Unfortunately this is not what I was looking for. I am looking for something similar:
    OR I want to make a table with .PNG file extensions and its full path under a root folder.


    Number

    File Name and Path

    Date Created

    File Size

    1

    D:\MyFolder-Root \Abcdefgh-1.png

    2014-03-25

    10 K

    2

    D:\MyFolder-Root \Abcdefgh-2.png

    2014-03-22

    3k

    3

    D:\MyFolder-Root \Abcdefgh-3.png

    2014-03-22

    6k

    4

    D:\MyFolder-Root\SUBFolder1\12345.png

    2014-03-22

    20k

    5

    D:\MyFolder-Root\SUBFolder1\12345-a.png

    2014-03-22

    34K

    …..

    D:\MyFolder-Root\SUBFolder1\ChildofSubFolder1\XYZ.png

    2014-03-22

    39K

    400

     

     

     


    N.A.Malik


    • Edited by N A Malik Tuesday, March 25, 2014 11:45 AM
    Tuesday, March 25, 2014 11:44 AM
  • What you are doing is trying to badger everyone into writing a script to you specifications.  You are making no effort to learn or understand.  THat is not what this forum is for. It is for technicians who use PowerShell or are learning to use PowerShell.

    If you cannot understand what is happening or do not care to try and learn thenplease consider hiring a consultant to do your script.

    I posted this script earlier. It generates a numbered list to a file. It is what you asked for.

    If you want a fancier output you will need to start learning how to write a script:

    $i=1;Get-ChildItem  -rec -File |%{'{0,8}    {1}' -f $i++,$_.Fullname} |ConvertTo-Html


    ¯\_(ツ)_/¯

    Tuesday, March 25, 2014 2:10 PM
  • Hi Jrv,

    I am not forcing someone to write a script for me.

    Rather I was just trying to give a detailed or easy to understand way to Scripting professionals what I want to do. That's true, I am not learning PowerShell script since this is not my area of interest and I CAN NOT hire a scripting pro to write a line of sentence for me in couple of years.
    My area of interest is deployment and in those forums we never had this kind of arguments, neither me or other pros or experts. This forum I believe is special because guys are seems to more arrogance , I had same feeling with a guy before .... any ways thanks for comment.


    N.A.Malik

    Wednesday, March 26, 2014 7:29 AM
  • Rather I was just trying to give a detailed or easy to understand way to Scripting professionals what I want to do. That's true, I am not learning PowerShell script since this is not my area of interest and I CAN NOT hire a scripting pro to write a line of sentence for me in couple of years.

    It seems you have an unrealistic expectation that you can post a script specification and others will write the code for you. It is like you are saying: "I don't have time to learn scripting, but I want you guys to translate my request into code for me for free, because my time is more valuable than yours."

    To clarify: The purpose of this forum is to answer scripting questions, not write code for others to spec. Remember, the help here is free, and we're volunteers.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Monday, May 19, 2014 10:11 PM
    Wednesday, March 26, 2014 2:22 PM