amikego
Goto Top

Verknüpfungen von leeren Ordnern löschen

Hallo,
ich schreibe gerade ein Skript mit Batch das leere Ordner mit Unterordner löscht.
Jetzt will ich es ein wenig ausarbeiten und hinzufügen das es leere Ordnerverknüpfungen löscht.
Leider habe ich keine Ahnung wie das gehen soll, da ich einen Loop drinhabe und ich nicht weiß wie das machen soll.

Hier ist mein derzeitiger Code.
@echo off

::start path / Variables
set startdir="C:\Users\armin\Desktop"   

::Initialize the Variable
set /a loop=0

::Directory c:\temp\ will be created, if the folder not exists 
if not exist c:\temp\ md c:\temp\

::if the directory c:\temp\tmp.txt exists, it will be deleted 
if exist c:\temp\tmp.txt del /F /Q c:\temp\tmp.txt

::Create Logfile for Deleted Filetypes in C:\Log\LOG_Useless_File_Killer.log
echo --------------------------------------------------------------- >> C:\Log\LOG_Useless_File_Killer.log	
echo Logfile from: %date% at %time% >> C:\Log\LOG_Useless_File_Killer.log

::this 5 Filetypes are going to be deleted immediately
del C:\Users\armin\Desktop\Thumbs.db /f /q /s >> C:\Log\LOG_Useless_File_Killer.log 
del C:\Users\armin\Desktop\desktop.ini /f /q /s >> C:\Log\LOG_Useless_File_Killer.log 
del C:\Users\armin\Desktop\*.DS_Store /f /q /s >> C:\Log\LOG_Useless_File_Killer.log 
del C:\Users\armin\Desktop\*._DS_Store /f /q /s >> C:\Log\LOG_Useless_File_Killer.log 
del C:\Users\armin\Desktop\*.desktop /f /q /s >> C:\Log\LOG_Useless_File_Killer.log && echo --------------------------------------------------------------- >> C:\Log\LOG_Useless_File_Killer.log

::Creates a Logfile for Empty Folders at C:\Log\LOG_Empty_Folder_Killer.log
echo ------------------------------------------------------------------ >> C:\Log\LOG_Empty_Folder_Killer.log
echo Logfile from: %date% at %time% >> C:\Log\LOG_Empty_Folder_Killer.log

::Writes the directorys in c:\temp\tmp.txt. 
dir /AD /b /s %startdir% >> c:\temp\tmp.txt

::at goto start it will be start again
:start 

::the Variable %loop% is increased by 1  
set /a loop =%loop%+1

::at 5 --> goto exit
if %loop%==5 goto exit

::Under 5 --> goto start 
else goto start

::deletes every empty folder which is wrote in C:\temp\tmp.txt & writes the deleted folders in C:\Log\LOG_Empty_Folder_Killer.log
for /F "delims=" %%i in (c:\temp\tmp.txt) do rd "%%i" && echo %%i >> C:\Log\LOG_Empty_Folder_Killer.log  

::--> goto start and begins again 
goto start

::%loop% has reached 5 --> exit
:exit

::Console window will be closed 
exit

pause 

exit

Vllt kann mir noch jemand bei etwas anderem helfen?
Ich möchte auch noch machen das wenn ein Ordner erstellt worden ist und er nach 2 Tagen immer noch leer ist das er da gelöscht wird.
Also das Ordner nach 2 Tager ihrer Erstellung und leer sind gelöscht werden sonst nicht.
Habe auch schon diverses Probiert (delage32,forefiles) und auch schon fast das ganze Internet durchforstet nur nicht gefunden bzw verstanden wie ich das umsetzen kann.
Es sollte aber mit Batch sein :/


Bin ein kompletter Anfänger in Sachen Skripting ;)

Vielen Dank schon mal für eure Hilfe

Mit freundlichen Grüßen Armin

Content-Key: 275396

Url: https://administrator.de/contentid/275396

Printed on: April 26, 2024 at 23:04 o'clock

Mitglied: 114757
114757 Jun 23, 2015 updated at 12:07:30 (UTC)
Goto Top
Moin Armin,
mit Powershell komplett (Entfernen von leeren Ordnern und toten Links), Pfad in Zeile 2 anpassen und freuen face-wink
# Pfad anpassen
$path = "C:\temp"  

function Remove-DeadLinks([string]$folder){
    $shell = New-Object -Com WScript.Shell
    gci $folder -Filter *.lnk -Recurse | %{
        if (!(Test-Path ($shell.CreateShortcut($_.FullName)).TargetPath)){
            write-host "Lösche toten Link: '$($_.Fullname)'"  
            remove-item $_.FullName -Force
        }
    }
}
function Remove-EmptyFolders([string]$folder){
    gci $folder -Recurse | ?{$_.PSIsContainer -and !(gci $_.Fullname -Recurse | ?{!$_.PSIsContainer})} | remove-item -Force -Recurse -EA SilentlyContinue -Whatif
}
# Entferne leere Ordner
Remove-EmptyFolders $path
# Entferne tote Links
Remove-DeadLinks $path
Gruß jodel32
Member: AmiKego
AmiKego Jun 23, 2015, updated at Jun 24, 2015 at 12:22:04 (UTC)
Goto Top
Hallo jodel,

Vielen Dank für deine Antwort
Nur habe ich das Problem das es in Batch sein sollte :/
Vllt kannst du mir damit auch noch weiterhelfen face-smile

Und bin gerade dabei, das mit dem Löschen der leeren Ordner nach 2 Tagen der Erstellung herauszufinden.. Nur weis ich nicht recht wie das gehen soll..
Vllt kann mir da auch noch jemand helfen


Grüße Armin