جزاك الله خير دوره مفيده طبعآ استمر واحتسب الاجر بارك الله فيك
 

توقيع : أبـو محـمد
جزاك الله كل خير أخي الكريم
متابع
تحياتي اليك
 
توقيع : megatron
جزاك الله خير وبارك فيك
 
توقيع : الفارس الفلسطيني
جزاك الله خير وبارك فيك
 
توقيع : الفارس الفلسطيني
كود:
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.

Temporary files were not deleted successfully.

FastStoneEditor1.webp
 
توقيع : Ghost rider7Ghost rider7 is verified member.
بارك الله فيك اخي الكريم
 
توقيع : mha1m
شكرا جدا لك
 
لايوجد استفاده من الدوره .. لا اعلم هل هناك عزوف وقلة دخول للمنتدى بشكل عام ام ان الموضوع نقل لقسم الدخول اليه قليل ..

ما
السلام عليكم
في الوقت الحالي سيكون المستفيدون من الدورة قلائل .. فلا تنزعج لهذا الأمر
ممكن يستفاد من دورتك لاحقاً .. المهم تبقى محفوظة وأجرك من الله على تعبك واجتهادك
بإذن الله لي عودة للاطلاع أكثر والاستفادة
جزاك الله خيراً
 
توقيع : MaskFD
جزاك الله خير وبارك فيك
 
توقيع : أسيرالشوق
بارك الله فيك اخى استمر دورة ممتازة
 
توقيع : Ghost abdou
تسلم ايدك يا بطل
 
توقيع : قبض الريح
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"
هذا الكود بالكامل اتمنى التجربه ثم محاولة فهم الكود وطرح الاساله ان وجد .. وسيتم الشرح لاحقا​
upload_2024-1-11_6-14-29.webp
 
توقيع : MesterPerfectMesterPerfect is verified member.
بعض التحسينات على الكود ثم النتيجة

upload_2024-1-11_6-18-23.webp


الكود مع التعديلات التي أجريتها

PHP:
# 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
 
توقيع : MesterPerfectMesterPerfect is verified member.
ما شاء الله عليك تسلم
 
توقيع : SystemBreaker
attachment.php
 
جزاك الله خير الجزاء جارى المتابعة والتطبيق
 
توقيع : Mohamed@tito
:rose::rose::rose: جزاكم الله من خير أعمالكم :rose::rose::rose:
:rose::rose::rose: متابع معكم ... إنشاء الله :rose::rose::rose::rose:
 
دورة قيمة و معلومات ثمينه جزاك الله خيرا وبارك فيك
 
بارك الله فيك
 
عودة
أعلى