أبـو محـمد
زيزوومي VIP
غير متصل
من فضلك قم بتحديث الصفحة لمشاهدة المحتوى المخفي
قم بمتابعة الفيديو أدناه لمعرفة كيفية تثبيت موقعنا كتطبيق ويب على الشاشة الرئيسية.
ملاحظة: قد لا تكون هذه الميزة متاحة في بعض المتصفحات.
PS C:\Users\loki\Desktop>
PS C:\Users\loki\Desktop> # Define the path to the temporary files folder
PS C:\Users\loki\Desktop> $tempFolderPath = $env:TEMP
PS C:\Users\loki\Desktop>
PS C:\Users\loki\Desktop> # Get a list of all files in the temporary folder
PS C:\Users\loki\Desktop> $tempFiles = Get-ChildItem -Path $tempFolderPath
PS C:\Users\loki\Desktop>
PS C:\Users\loki\Desktop> # variable to hold number of deleted items
PS C:\Users\loki\Desktop> $Del = 0
PS C:\Users\loki\Desktop>
PS C:\Users\loki\Desktop> # variable to hold number of not deleted items
PS C:\Users\loki\Desktop> $NotDel = 0
PS C:\Users\loki\Desktop>
PS C:\Users\loki\Desktop> # Loop through each file and delete it
PS C:\Users\loki\Desktop> foreach ($file in $tempFiles) {
>>
>>
>> # use Try $ Catch for error handling
>> try {
>>
>> #delete temp files
>> Remove-Item -Path $file.FullName -Recurse -Force -ErrorAction Stop
>>
>> # increase count of deleted item by 1
>> $Del = $Del + 1
>>
>> #Display a message if deleted successfully
>> Write-Host "[$Del] Deleted: $($file.FullName)" -ForegroundColor "Green"
>>
>> # pause
>> Start-Sleep -Milliseconds 50
>>
>> } catch {
>>
>> # increase count of not deleted item by 1
>> $NotDel = $NotDel + 1
>>
>> #Display a message if deleted successfully
>> Write-Host "[$NotDel] Error deleting file: $($file.FullName)" -ForegroundColor "Red"
>>
>> # pause
>> Start-Sleep -Milliseconds 50
>> }
>> }
PS C:\Users\loki\Desktop>
PS C:\Users\loki\Desktop> # Display colored messages
PS C:\Users\loki\Desktop> Write-Host "$Del Temporary files deleted successfully." -ForegroundColor "Yellow"
0 Temporary files deleted successfully.
PS C:\Users\loki\Desktop> Write-Host "$NotDel Temporary files were not deleted successfully." -ForegroundColor "Blue"
0 Temporary files were not deleted successfully.
لايوجد استفاده من الدوره .. لا اعلم هل هناك عزوف وقلة دخول للمنتدى بشكل عام ام ان الموضوع نقل لقسم الدخول اليه قليل ..
ما
PHP:# Define the path to the temporary files folder $tempFolderPath = $env:TEMP # Get a list of all files in the temporary folder $tempFiles = Get-ChildItem -Path $tempFolderPath # variable to hold number of deleted items $Del = 0 # variable to hold number of not deleted items $NotDel = 0 # Loop through each file and delete it foreach ($file in $tempFiles) { # use Try $ Catch for error handling try { #delete temp files Remove-Item -Path $file.FullName -Recurse -Force -ErrorAction Stop # increase count of deleted item by 1 $Del = $Del + 1 #Display a message if deleted successfully Write-Host "[$Del] Deleted: $($file.FullName)" -ForegroundColor "Green" # pause Start-Sleep -Milliseconds 50 } catch { # increase count of not deleted item by 1 $NotDel = $NotDel + 1 #Display a message if deleted successfully Write-Host "[$NotDel] Error deleting file: $($file.FullName)" -ForegroundColor "Red" # pause Start-Sleep -Milliseconds 50 } } # Display colored messages Write-Host "$Del Temporary files deleted successfully." -ForegroundColor "Yellow" Write-Host "$NotDel Temporary files were not deleted successfully." -ForegroundColor "Blue"
هذا الكود بالكامل اتمنى التجربه ثم محاولة فهم الكود وطرح الاساله ان وجد .. وسيتم الشرح لاحقا
# Define the path to the temporary files folder
$tempFolderPath = $env:TEMP
# Get a list of all files and folders in the temporary folder, including hidden items
$tempFiles = Get-ChildItem -Path $tempFolderPath -Force -Include *
# Initialize counters for deleted and not deleted items
$deletedCount = 0
$notDeletedCount = 0
# Loop through each item and attempt to delete it
foreach ($file in $tempFiles) {
try {
# Use '-Recurse' to delete folders and their contents, and '-Force' to override read-only attributes
Remove-Item -Path $file.FullName -Recurse -Force -ErrorAction Stop
# Increment deleted count and display success message
$deletedCount++
Write-Host "[$deletedCount] Deleted: $($file.FullName)" -ForegroundColor Green
} catch {
# Increment not deleted count and display error message
$notDeletedCount++
Write-Host "[$notDeletedCount] Error deleting file/folder: $($file.FullName) - $($_.Exception.Message)" -ForegroundColor Red
}
# Brief pause between deletions (optional for visual clarity)
Start-Sleep -Milliseconds 50
}
# Display summary messages
Write-Host "$deletedCount Temporary files/folders deleted successfully." -ForegroundColor Yellow
Write-Host "$notDeletedCount Temporary files/folders were not deleted successfully." -ForegroundColor Blue