Extra files are not deleted by script

September 7, 2020 at 02:55:21
Specs: Windows 10
Hello everyone! I have script:
@echo off
call :init
call :cleanup
pause
@echo on
@exit /b %ec_success%

:init
    set /a "ec_success=0"
    set /a "ec_failed=1"

    set "log=decktop cleanup.log"
exit /b %ec_success%

:cleanup
    set "__from=%__CD__%"
    set "__desktop=C:\Users\%username%\Desktop"

    set "items[0]=Rider.lnk"
    set "items[1]=Visual Studio 2019.lnk"
    set "items[2]=Visual Studio Code.lnk"
    set "items[3]=Visual Studio Code.lnk"
    set "items[4]=Blender.lnk"
    set "items[5]=Paint.NET.lnk"
    set "items[6]=ONLYOFFICE Editors.lnk"
    set "items[7]=Firefox.lnk"

    cd "%__desktop%"

    for %%f in (*.lnk) do (
        call :is_in_array "" "%%f"
        if %errorLevel% equ 1 del "%%f"
    )

    cd "%__from%"
exit /b %ec_success%

:is_in_array
    set /a "__ec_array_value_not_found=1"
    set /a "__ec_array_name_is_not_passed=2"
    set /a "__ec_value_is_not_passed=3"

    set "__array=%~1"
    set "__value=%~2"
    set /a "__i=0"
    
    if "%~1" == "" exit /b %__ec_array_name_is_not_passed%
    if "%__value%" == "" exit /b %__ec_value_is_not_passed%
    
    setlocal enabledelayedexpansion
    :while_end_is_not_reached
    if not "!%__array%[%__i%]!" == "" (
        if "!%__array%[%__i%]!" == "%__value%" exit /b %ec_success%
        set /a "__i+=1"
        goto :while_end_is_not_reached
    )
    setlocal disabledelayedexpansion
exit /b %__ec_array_value_not_found%

but it doesn't work. I want to remove all .lnk files from Desktop that are not in items array.

message edited by AlvinSeville7cf


See More: Extra files are not deleted by script


#1
September 7, 2020 at 22:16:16
No offense, but it won't be easy for a helper to figure the struture.
I can't follow my own code a week after I write it.

Say what it did, or didn't did.

As we learned in 4th grade, neatness & originality are important, but so is spelling.

You have 3 instances of desktop and 1 of decktop.
Doesn't seem promising.

And this gives me the heebie-jeebies:
set "log=decktop cleanup.log"

=====================

M2


Reply ↓  Report •
Related Solutions


Ask Question