Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guys, Not sure if I can post any batch file related question in this forum. If this is not appropriate, please let me know. Thanks in advance.
In any case, here is my quest looking for resolution if possible. I use this code to delete files and folders but I want to know how many files and folders being deleted. A volunteer suggests a powershell script to count the total files before deletion but my concern is there may be some files denying deletion which make the count result not accurate.
Here is the PS code suggested from voluteer :
In any case, here is my quest looking for resolution if possible. I use this code to delete files and folders but I want to know how many files and folders being deleted. A volunteer suggests a powershell script to count the total files before deletion but my concern is there may be some files denying deletion which make the count result not accurate.
VBA Code:
REM Remove All Files older than 180 days
forfiles /p "%windir%\ABC\Log" /s /m *.* /d -180 /c "cmd /c del /f /q @path"
REM Remove Folders with specified folder name
For /D %%F ("%windir%\ABC\Log\*-*-*") do rd /s /q "%%F"
Here is the PS code suggested from voluteer :
Code:
set-location d:\testing -ErrorAction stop # Change directory
$files = get-childitem -File # Get all the files in this directory
$count = ($files|measure).count # ($files|measure).count gives how
# many files are in this collection.
write-host "There are $($count) files to be deleted." # Write that to the screen.
$files | remove-item #remove the files