Okay, I can come up with the follwoing code and it works:
$now=Get-Date -format "yyyyMMdd"
Get-ChildItem "G:\Import\DataIn\*.*_$now`*.*" | Sort-Object fullname | Select CreationTime, FullName, Length | Export-Csv -Force -NoTypeInformation "G:\Import\Logs\Filelist$now.csv"
However, in my output, I want to separate the date and time into two separate columns. Furthermore, I want to have a separate file that contains two 'fields' and will be in the format of filename.filetype, description
. The filename.filetype
portion will match the *.* above (e.g. everything from the start of the filename, up to the first '.', and following, up to the first underscore, and I want to include the value of description
from the file.
So, if I have a directory that contains the following filenames:
And my 'description' file contains:
input_file1.txt,The description for file1
input_file2.txt,The description for file2
input_file3.txt,The description for file3
And I run this code on 11.19.2014, the expected output into csv format should be:
The description for file1","filesize"
The description for file2","filesize"
The description for file3","filesize"
Where yyyy/mm/dd represents the file creation date of each file, hh:mm:ss represents the file creation time of each file, "filesize" represents the file size of each file and "The description for file#" is the description (second) field of the "description" file after matching "input_file#.txt" portion of the filename (example actual filenames are: "acctstd.txt_yyyymmdd_hhmm
s", in which case, the "description file would contain entries for "acctstd.txt", "TOS_SAN.xml" and "sect298.html"). Hope this is clear.
p.s. If I have a file that does not have a corresponding match in the 'description' file, I would just want to include "unknown" for the Description.