Listing files and folders into a document.

Its always been annoying that it isnt trivial to get a list of documents. This powershell code let you create an excel compatible CSV file listing all the files and folders, one with the newest (by creation data) files first.


function export-file-list
{
param ( $foldername)
echo $foldername
$csvfilename1=($foldername + "\dir_listing_by_creation_time.csv")
$csvfilename2=($foldername + "\dir_listing_by_name.csv")
$t = get-childitem -recurse  $foldername |  select fullname, name, lastwritetime, creationtime
foreach ( $f in $t ) {
    $f | fl
	$f1="."+$f.fullname.substring($foldername.length)
	$f.fullname=$f1
    $f1=$f.fullname.substring(0,$f.fullname.length-$f.name.length)
    $f1
    $f | fl
    $f.fullname=$f1
}

$t | select @{Name="Folder";Expression={$_."Fullname"}} , name , lastwritetime , creationtime |  sort creationtime  -descending | export-csv -notypeinformation $csvfilename1
$t  | select @{Name="Folder";Expression={$_."Fullname"}} , name , lastwritetime , creationtime | export-csv -notypeinformation $csvfilename2


}                                                     

export-file-list (  "d:\Shares\Data" )

About Jeff Turner

Technical director of Nano Tera Network Solutions.
This entry was posted in Uncategorized. Bookmark the permalink.