Hello everyone! I have script that you can look here or within GitHub Gist. It is planned to clean up Desktop via this script: all files those names are in items must be preserved and others must be trashed. But script doesn't work: no files removed after it execution. is_in_array function doesn't work properly. How to fix it?
Code:
@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 "%__array%" == "" 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%
Last edited: