19 gennaio 2013

Check if a file or folder exists with dos command

You can use the IF EXIST statement to check for the presence of a file or directory:

To check if the file "file.exe" exists in the directory temp:
IF EXIST c:\temp\file.exe ECHO File exists!
 
To check if a the directory "temp" exists (Notice the nul):
IF EXIST c:\temp\nul ECHO Directory exists! 
 
Regards

how check process or application is running with Dos command


I show two simple script:

  • Below check if an application is running:

@echo off
tasklist /FI "IMAGENAME eq process_app.exe" 2>NUL | find /I /N "process_app.exe">NUL
if "%ERRORLEVEL%"=="0" echo Programm is running
if "%ERRORLEVEL%"=="1" echo Programm is not running 
 
  • Below check if a process is running:
@echo off 
tasklist /FI "SERVICES eq process_name" 2>NUL | find /I /N "process_file.exe">NUL
if "%ERRORLEVEL%"=="1" goto Process_NotFound
if "%ERRORLEVEL%"=="0" goto Process_Found 
 
 
Regards

how check free disk space with command dos


I will show below a simple code in order to check the free disk space with few Dos commands:


@echo off
for /f "tokens=2" %%S in ('wmic volume get DriveLetter^, FreeSpace ^| findstr "^C:"') do set freeSpace=%%S
rem if the freespace is less than 1GB then execute blat.exe to send an email 
if %freeSpace% leq 1000000000 "c:\Blat\blat.exe ...." 
@echo on
rem now, show the freespace 
@echo %freeSpace%
 
 
Remember to change the drive letter, in the example I have checked the drive C.
Regards