Back then I must have performed some incompetent shallow tests - because the above does not really work now
And also this version [that for tests purposes targets all kinds of XLSM files and not just hidden ones] also does not work
Code: Select all
@echo off
chcp 65001 >nul
:: ███ preparations ███
setlocal EnableDelayedExpansion
set "PATTERN_OF_FILES=~$*.XLSM"
set "LIST_OF_VOLUMES_TO_BE_SCANNED=B Q T" REM This is a very limited list for test purposes
:: set "LIST_OF_VOLUMES_TO_BE_SCANNED=C D E F G H I J K L M N O P Q R S T U V W X Y Z" REM This is not a full list
:: set "LIST_OF_VOLUMES_TO_BE_SCANNED=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" REM This is the full list i.e. from A to Z
set "FILES_DELETED="
set "FILES_NOT_DELETED="
set "VOLUMES_INACCESSIBLE="
set "VOLUMES_OMITTED="
set "VOLUMES_PROCESSED="
echo Deleting [not only hidden but temporarily] all files matching this pattern:
:: echo Deleting hidden files matching this pattern:
echo.
echo %PATTERN_OF_FILES%
echo.
echo.
echo.
echo List of volumes:
echo.
:: ███ volumes list ███
::
:: This shows status of volumes
::
for %%V in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
set "FOUND_VOLUME=0"
for %%D in (%LIST_OF_VOLUMES_TO_BE_SCANNED%) do (
if "%%V"=="%%D" set "FOUND_VOLUME=1"
)
if "!FOUND_VOLUME!"=="1" (
if exist "%%V:\" (
echo %%V + scannable
) else (
echo %%V - absent
)
) else (
echo %%V • omitted
set "VOLUMES_OMITTED=!VOLUMES_OMITTED!%%V "
)
)
echo.
echo.
echo.
:: ███ progress info ███
::
:: This adds valuable info - because the scanning of volumes can take several minutes, depending on number of volumes present in the operating system and speed of drives
::
set /p "=Process is in progress..." <nul
:: ███ deletion ███
::
:: The below performs deletion on listed volumes
::
for %%D in (%LIST_OF_VOLUMES_TO_BE_SCANNED%) do (
set "A_DRIVE=%%D:\"
if exist "!A_DRIVE!" (
set "VOLUMES_PROCESSED=!VOLUMES_PROCESSED!%%D "
for /f "delims=" %%F in ('dir "!A_DRIVE!!PATTERN_OF_FILES!" /a /b /s 2^>nul') do (
del /a /f /q "%%F" >nul 2>&1
if exist "%%F" (
set "FILES_NOT_DELETED=!FILES_NOT_DELETED!%%F|"
) else (
set "FILES_DELETED=!FILES_DELETED!%%F|"
)
)
) else (
set "VOLUMES_INACCESSIBLE=!VOLUMES_INACCESSIBLE!%%D "
)
)
:: ███ progress info removal ███
::
:: The below overwrites the line >>Clear "Process is in progress...<<
::
<nul set /p=[1A[2K
echo.
:: ███ report ███
::
:: This produces a detailed report
::
:: Excess of pause signs in >> Volumes scanned: << is a workaround needed for the above process of overwriting of the >>Process is in progress...<< line to work correctly
::
echo Volumes scanned:
echo.
if defined VOLUMES_PROCESSED (
echo !VOLUMES_PROCESSED!
) else (
echo [NONE]
)
echo.
echo.
echo.
echo Volumes blacklisted from being accessed:
echo.
if defined VOLUMES_OMITTED (
echo !VOLUMES_OMITTED!
) else (
echo [NONE]
)
echo.
echo.
echo.
echo Volumes not accessible or missing:
echo.
if defined VOLUMES_INACCESSIBLE (
echo !VOLUMES_INACCESSIBLE!
) else (
echo [NONE]
)
echo.
echo.
echo.
echo Deleted files:
echo.
if defined FILES_DELETED (
for %%F in ("!FILES_DELETED:|=" "!") do (
if "%%~F" NEQ "" echo %%~F
)
) else (
echo [NONE]
)
echo.
echo.
echo.
echo Deletion failed for:
echo.
if defined FILES_NOT_DELETED (
for %%F in ("!FILES_NOT_DELETED:|=" "!") do (
if "%%~F" NEQ "" echo %%~F
)
) else (
echo [NONE]
)
:: ███ end ███
endlocal
echo.
echo.
echo.
echo ────────────────────────────────
echo Additional temporary debugging ─ content that is still left in a test folder after supposed deletion:
echo ────────────────────────────────
echo.
echo.
echo.
dir "T:\! Excel files deletion test\~$*.xlsm" /a /b /s
echo.
echo.
echo.
pause
because no matter how many times I execute it, its console window report will always show
Deleting [not only hidden but temporarily] all files matching this pattern:
~$*.XLSM
List of volumes:
A • omitted
B - absent
C • omitted
D • omitted
E • omitted
F • omitted
G • omitted
H • omitted
I • omitted
J • omitted
K • omitted
L • omitted
M • omitted
N • omitted
O • omitted
P • omitted
Q - absent
R • omitted
S • omitted
T + scannable
U • omitted
V • omitted
W • omitted
X • omitted
Y • omitted
Z • omitted
Volumes scanned:
T
Volumes blacklisted from being accessed:
A C D E F G H I J K L M N O P R S U V W X Y Z
Volumes not accessible or missing:
B Q
Deleted files:
T:\ Excel files deletion test\hidden\~$test file for potential deletion - Copy.xlsm
T:\ Excel files deletion test\hidden\~$test file for potential deletion.xlsm
T:\ Excel files deletion test\hidden and read only\~$test file for potential deletion - Copy.xlsm
T:\ Excel files deletion test\hidden and read only\~$test file for potential deletion.xlsm
T:\ Excel files deletion test\ordinary\~$test file for potential deletion - Copy.xlsm
T:\ Excel files deletion test\ordinary\~$test file for potential deletion.xlsm
T:\ Excel files deletion test\ordinary\~$~$test file for potential deletion.xlsm
T:\ Excel files deletion test\read only\~$test file for potential deletion - Copy.xlsm
T:\ Excel files deletion test\read only\~$test file for potential deletion.xlsm
Deletion failed for:
[NONE]
────────────────────────────────
Additional temporary debugging ─ content that is still left in a test folder after supposed deletion:
────────────────────────────────
T:\! Excel files deletion test\hidden\~$test file for potential deletion - Copy.xlsm
T:\! Excel files deletion test\hidden\~$test file for potential deletion.xlsm
T:\! Excel files deletion test\hidden and read only\~$test file for potential deletion - Copy.xlsm
T:\! Excel files deletion test\hidden and read only\~$test file for potential deletion.xlsm
T:\! Excel files deletion test\ordinary\~$test file for potential deletion - Copy.xlsm
T:\! Excel files deletion test\ordinary\~$test file for potential deletion.xlsm
T:\! Excel files deletion test\ordinary\~$~$test file for potential deletion.xlsm
T:\! Excel files deletion test\read only\~$test file for potential deletion - Copy.xlsm
T:\! Excel files deletion test\read only\~$test file for potential deletion.xlsm
So the problem is that the report lies about code deleting even ordinary files [i.e. those without attributes]. And also that at the same time it fails to report orchestrated by me failure of deletion of even the ordinary file
T:\! Excel files deletion test\ordinary\~$test file for potential deletion.xlsm
which for test purposes I keep opened in Excel, which causes to appear the
T:\! Excel files deletion test\ordinary\~$~$test file for potential deletion.xlsm
temporary hidden file [and which extra file is, also intentionally, not being deleted]
I now have went through numeral revisions and always failed - which drives me mad, because this simplistic test UTF-8 BAT works A-OK
Code: Select all
@echo off
chcp 65001 >nul
del /a /f /q /s "T:\! Excel files deletion test"
pause
i.e. it deletes all files in that targeted test folder and its sub-folders with exception of [planned as a test] XLSM file that is on purpose opened in Excel [thus blocked] - and then this test code reports about the process truthfully:
Deleted file - T:\! Excel files deletion test\hidden\~$test file for potential deletion - Copy.xlsm
Deleted file - T:\! Excel files deletion test\hidden\~$test file for potential deletion.xlsm
Deleted file - T:\! Excel files deletion test\hidden and read only\~$test file for potential deletion - Copy.xlsm
Deleted file - T:\! Excel files deletion test\hidden and read only\~$test file for potential deletion.xlsm
Deleted file - T:\! Excel files deletion test\ordinary\~$test file for potential deletion - Copy.xlsm
T:\! Excel files deletion test\ordinary\~$test file for potential deletion.xlsm
The process cannot access the file because it is being used by another process.
T:\! Excel files deletion test\ordinary\~$~$test file for potential deletion.xlsm
The process cannot access the file because it is being used by another process.
Deleted file - T:\! Excel files deletion test\read only\~$test file for potential deletion - Copy.xlsm
Deleted file - T:\! Excel files deletion test\read only\~$test file for potential deletion.xlsm