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
Nov 07, 2022Iron Contributor
Hi @Oliwer Sundgren on which row should be the scheduled task if I wan to add it there?
Alan2022
Nov 10, 2022Iron Contributor
AtanasM
On the scheduler task.
You can create a batch file which will call the powershell script.
Then add that batch file to the scheduler task.
Test.bat
Start /wait powershell.exe -command "& 'C:\Scripts\deletecompletedfiles.ps1'"
- AtanasMNov 11, 2022Iron ContributorHi Alan2022 thanks for the proposal
I have the following script used for deletion of excel files, but since 1 month doesn't work anymore. It seems, that Excel doesn't recognize the file names. Could you check it:
param([string]$Loeschpfad)
Start-Sleep -Seconds 2
Unblock-File "C:\Users\user\Desktop\script.ps1"
Remove-Item $Loeschpfad- Alan2022Nov 14, 2022Iron Contributor
AtanasM
Hi,
How about this one?Clear-Host # Extract List of XLSX Files $xlsxLocation = "C:\temp\*.xlsx" $xlsxFiles = Get-ChildItem -Path $xlsxLocation -Recurse -Force | Sort-Object LastWriteTime # List every XLSX Files foreach($xlsxFile in $xlsxFiles){ Write-Host $xlsxFile.Fullname # Remove-Item -Path $xlsxFile.Fullname }