Forum Discussion
AtanasM
Nov 03, 2022Iron Contributor
Script to delete automatically all incoming files in a folder.
Employee receives daily orders in excel files. If he completes the order, the file is moved to the folder "Completed orders". A PowerShell script is needed to delete automatically the files in the ...
- Nov 20, 2022
Hi,
This script will delete all excel in Completed orders.
Note the remove item is being remarked.
Also removing -recurse parameter will not check sub folders.Clear-Host # Extract List of XLSX Files $xlsxLocation = "C:\Completed orders\*.xlsx" $xlsxFiles = Get-ChildItem -Path $xlsxLocation -Force | Sort-Object LastWriteTime # List every XLSX Files foreach($xlsxFile in $xlsxFiles){ Write-Host $xlsxFile.Fullname # Remove-Item -Path $xlsxFile.Fullname }
AtanasM
Iron Contributor
Hi Alan2022 this script deletes the related files, but deletes also the connected subfolders. Do you know a solution for this?
Alan2022
Nov 20, 2022Iron Contributor
Hi,
This script will delete all excel in Completed orders.
Note the remove item is being remarked.
Also removing -recurse parameter will not check sub folders.
Clear-Host
# Extract List of XLSX Files
$xlsxLocation = "C:\Completed orders\*.xlsx"
$xlsxFiles = Get-ChildItem -Path $xlsxLocation -Force | Sort-Object LastWriteTime
# List every XLSX Files
foreach($xlsxFile in $xlsxFiles){
Write-Host $xlsxFile.Fullname
# Remove-Item -Path $xlsxFile.Fullname
}