i need to check on a branch if it has any files other than desktop.ini

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

i need to check on a branch if it has any files other than desktop.ini

#1 Post by nnnmmm » 20 Oct 2023 10:50

would someone like to write this batch for me?

if "%USERPROFILE%\Pictures" 's current directory or subdirectories have any files other than desktop.ini then
play C:\Windows\Media\chord.wav (if not easy , then beep pc speaker )
and echo "alert"

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: i need to check on a branch if it has any files other than desktop.ini

#2 Post by Batcher » 20 Oct 2023 19:01

test-1.bat

Code: Select all

@echo off
set "YourFolder=%USERPROFILE%\Pictures"
if exist "%YourFolder%" (
    pushd "%YourFolder%"
    dir /b /a | findstr /v /x /i "desktop.ini" | findstr .*
    if not errorlevel 1 (
        start "" "C:\Windows\Media\chord.wav"
    )
    popd
)

nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

Re: i need to check on a branch if it has any files other than desktop.ini

#3 Post by nnnmmm » 21 Oct 2023 00:47

C:\Users\AAA\Pictures\Camera Roll\
C:\Users\AAA\Pictures\Saved Pictures\
C:\Users\AAA\Pictures\other game names\

the batch detects these as files. they can have directories, and programs always rebuild these directories, so no point to delete them, but i wont allow this kind of trash files in where OS is.

start "" "C:\Windows\Media\chord.wav" was more trouble than i thought, i uninstalled all windows software, including win media, there are absolutely no integrations with any file extensions. i think i will replace it with NirCMD for this, but kind of working slow. if beeping PC speaker is PASSIVELY possible without loading any software, i will take the code

thanks for the help

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: i need to check on a branch if it has any files other than desktop.ini

#4 Post by Batcher » 21 Oct 2023 03:04

test-2.bat

Code: Select all

@echo off
set "YourFolder=%USERPROFILE%\Pictures"
if exist "%YourFolder%" (
    pushd "%YourFolder%"
    dir /b /a-d | findstr /v /x /i "desktop.ini" | findstr .*
    if not errorlevel 1 (
        for /f %%i in ('mshta "VBScript:CreateObject("Scripting.Filesystemobject").GetStandardStream(1).Write(Chr(7))(Close)"') do (
            set "BEL=%%i"
        )
        for /l %%i in (1,1,3) do (
            echo,%BEL%
            ping -n 2 127.0.0.1 >nul
        )
    )
    popd
)

nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

Re: i need to check on a branch if it has any files other than desktop.ini

#5 Post by nnnmmm » 21 Oct 2023 04:15

Code: Select all

@echo off
set "YourFolder=%USERPROFILE%\Pictures"
if exist "%YourFolder%" (
    pushd "%YourFolder%"
    dir /b /a-d /s | findstr /v /x /i "desktop.ini" | findstr .* >NUL
    if not errorlevel 1 (
       echo ALERT
       pause
    )
    popd
)
this batch always shows ALERT, even though there are no other files other than desktop.ini
....because there might a file like screenshot01.jpg somewhere in %USERPROFILE%\Pictures's subdirectories....
please forget about beep or any sound play code

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: i need to check on a branch if it has any files other than desktop.ini

#6 Post by aGerman » 21 Oct 2023 04:43

JScript hybrid

Code: Select all

@if (0)==(0) echo off &setlocal &: Batch/JScript hybrid line
:: Batch part:

:: That's command to run the script file as JScript again.
set ^"playsound=cscript.exe //nologo //e:jscript "%~fs0" ^"

:: Recursive check where directories (-d) and system files (-s) are excluded. Typically desktop.ini files belong to the latter.
:: Conditionally execute the %playsound% command if the DIR command succeeded to find one ore more files.
>nul 2>&1 dir "%USERPROFILE%\Pictures" /a:-d-s /b /s && %playsound% "%SystemRoot%\Media\chord.wav"

goto :eof @end
// JScript part:
var player = new ActiveXObject('WMPlayer.OCX');
player.URL = WScript.Arguments(0);
if (!new ActiveXObject('Scripting.FileSystemObject').FileExists(player.URL)) { WScript.Quit(1); }
player.controls.play();
while (!player.currentMedia.duration) { WScript.Sleep(50); }
WScript.Sleep(parseInt(player.currentMedia.duration * 1000) + 1);
BEL character:

Code: Select all

@echo off &setlocal

:: Use FORFILES to get a BEL character. Put it in a command line that
:: a. sends it to the VT processor without printing a new line
:: b. waits a second for the bell to ring as it is played asynchronously on modern Windows versions
for /f %%b in (
  '%__APPDIR__%forfiles.exe /p "%__APPDIR__%." /m "cmd.exe" /c "%__APPDIR__%cmd.exe /q /d /c echo(0x07"'
) do set ^"ring=^<nul set /p "=%%b"^&^>nul "%__APPDIR__%ping.exe" -n 2 "127.0.0.1"^"

>nul 2>&1 dir "%USERPROFILE%\Pictures" /a:-d-s /b /s && %ring%
please forget about beep or any sound play code

Code: Select all

>nul 2>&1 dir "%USERPROFILE%\Pictures" /a:-d-s /b /s && echo ALERT
Steffen

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: i need to check on a branch if it has any files other than desktop.ini

#7 Post by Batcher » 21 Oct 2023 08:17

test-3.bat

Code: Select all

@echo off
set "YourFolder=%USERPROFILE%\Pictures"
if exist "%YourFolder%" (
    for /f "delims=" %%i in ('dir /b /s /a-d "%YourFolder%"') do (
        if /i "%%~nxi" neq "desktop.ini" (
            echo ALERT
        )
    )
)
pause

nnnmmm
Posts: 122
Joined: 26 Aug 2017 06:11

Re: i need to check on a branch if it has any files other than desktop.ini

#8 Post by nnnmmm » 21 Oct 2023 20:47

Code: Select all

@echo off
SET Q1=C:\ZTREE\NIRCMDC.EXE
SET Q2=C:\ZTREE\NIRCMDC-64.EXE
IF DEFINED PUBLIC (SET QQ=%Q2%) ELSE (SET QQ=%Q1%)

set "dir1=%USERPROFILE%\Pictures"
set "dir2=%USERPROFILE%\Downloads"
if exist "%dir1%" (
    for /f "delims=" %%i in ('dir /b /s /a-d "%dir1%"') do (
        if /i "%%~nxi" neq "desktop.ini" (
            echo ALERT: %dir1% has files
            %QQ% BEEP 1500 100 &%QQ% BEEP 600 100 &%QQ% BEEP 1100 100
        )
    )
)

if exist "%dir2%" (
    for /f "delims=" %%i in ('dir /b /s /a-d "%dir2%"') do (
        if /i "%%~nxi" neq "desktop.ini" (
            echo ALERT: %dir2% has files
            %QQ% BEEP 1500 100 &%QQ% BEEP 600 100 &%QQ% BEEP 1100 100
        )
    )
)
thanks very much it was done very nicely
i thought the batch coding of sound making was faster but NirCMDC was much much faster and clean.
and a batch coding from all your helps didnt make any sounds, it sort of hung for 3~4 seconds, it was probably because a PC speaker BEEP was NOT a real PC speaker BEEP, and probably was replaced with the direct sound emulating PC speaker BEEP behind my back, because when DOSBox-X emulates DOS programs, DOSBOX-X makes stereo PC speaker BEEP, loud and clean and more pleasing, and the frequency and duration of BEEP were exactly the same as what real PC speaker BEEP would have done.
this batch now makes its place in the startup dir.

PS, is it possible, when the code doesnt find any files, not to show "files not found" display output

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: i need to check on a branch if it has any files other than desktop.ini

#9 Post by Batcher » 21 Oct 2023 21:28

test-4.bat

Code: Select all

@echo off
set "YourFolder=%USERPROFILE%\Pictures"
if exist "%YourFolder%" (
    for /f "delims=" %%i in ('dir /b /s /a-d "%YourFolder%" 2^>nul') do (
        if /i "%%~nxi" neq "desktop.ini" (
            echo ALERT
        )
    )
)
pause

Post Reply