Tuesday, August 5, 2014

Using Powershell to create a Csv list of files in a folder

I wanted to be able to compare a list of files in a folder with a list I had from a table in the database.  There had to be a better way than just printing up the database list and checking them off one by one.  That's when I learned about Windows Powershell. Apparently Powershell is "Microsoft’s new command console and scripting language."  I found instructions on the internet on how to create a csv file of all the files in a folder using the Powershell cmdlet, Export-Csv.  From the Microsoft Technet site: "The Export-Csv cmdlet makes it easy to export data as a comma-separated values (CSV) file; all you need to do is call Export-Csv followed by the path to the CSV file."

When you install Windows Powershell, there is supposed to be a shortcut by clicking Start, pointing to All Programs, pointing to Windows PowerShell 1.0, and then clicking Windows PowerShell. Powershell was already installed on my computer, but I couldn't find it there and had to go to C:\Windows\System32\WindowsPowerShell\v1.0 to find PowerShell.exe.

To create a csv file of all the documents in C:\Users\djspecht\Documents and place the csv file in the same folder, the command would go like this. (Commands are not case sensitive.)

PS C:\> dir C:\Users\djspecht\Documents | export-csv C:\Users\djspecht\Documents\TestList.csv

No comments:

Post a Comment