Write a sample powershell script to parse the files in a directory
- User
Write a sample powershell script to parse the files in a directory
- Assistant
Sure, I'd be happy to help you with that! Here's a sample PowerShell script that will parse all the files in a given directory and display their names, sizes, and last modified dates:
powershell# Set the directory path you want to parse $directoryPath = "C:\Your\Directory\Path" # Check if the directory exists if (Test-Path $directoryPath) { # Get all files in the directory and its subdirectories $files = Get-ChildItem -Path $directoryPath -File -Recurse # Parse each file and display its name, size, and last modified date foreach ($file in $files) { $fileInfo = New-Object System.IO.FileInfo($file.FullName) Write-Host "File Name: " $fileInfo.Name Write-Host "File Size: " $fileInfo.Length "bytes" Write-Host "Last Modified: " $fileInfo.LastWriteTime Write-Host } } else { Write-Host "The specified directory does not exist." }Replace
"C:\Your\Directory\Path"with the path to the directory you want to parse. The script will recursively search for all files in the directory and its subdirectories, and display their names, sizes, and last modified dates.If you only want to parse files in the specified directory and not its subdirectories, remove the
-Recurseparameter from theGet-ChildItemcommand.Let me know if you have any questions or need further assistance!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.