how to tell if folder or drive has no files (is empty)

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

how can I tell if a folder or drive is empty via a dos batch file (no wsh
support for this)? It needs to be part of a batch file run from a win98 boot
disk. I need to test for this condition and take action only if the drive is
empty.

any ideas?

I think I could use the 'dir' and 'find' commands to do this by testing for
'file not found' but I was wondering if there was a more direct or better
approach than that.

anyone?

thanks in advance.
 
Not having a 98 boot disk or installed copy easily to hand, I can't test
anything but in your shoes I would probably try precisely the tools you
mentioned also searching on the number of files. Simply test the
errorlevel resulting from the search and proceed accordingly.
 
Dean Wells said:
Not having a 98 boot disk or installed copy easily to hand, I can't test
anything but in your shoes I would probably try precisely the tools you
mentioned also searching on the number of files. Simply test the
errorlevel resulting from the search and proceed accordingly.

Searching for "file not found will only tell you that the file you were
looking for was not there. What I think you want to know is: does this
folder contain ANY files or ANY subfolders.

You *could* do something like this:

set cfd=c
dir/s/a folder\*.* | find " 0 File(s) "
if errorlevel 1 set cfd=%cfd%f
dir/s/a folder\*.* | find " 2 Dir(s) "
if errorlevel 1 set cfd=%cfd%d

if "%cfd%"=="c" goto:isempty

echo/directory "folder" is NOT empty

I do not have 9x running either, and am basing the search strings on what
shows up when the dir/s/a command is run against an empty folder on XP. But
even on XP this will fail should there be files and/or folders whose names
contain the search strings.

/Al
--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
how can I tell if a folder or drive is empty via a dos batch file (no
wsh support for this)? It needs to be part of a batch file run from a
win98 boot disk. I need to test for this condition and take action
only if the drive is empty.

any ideas?

I think I could use the 'dir' and 'find' commands to do this by
testing for 'file not found' but I was wondering if there was a more
direct or better approach than that.

anyone?

thanks in advance.
 
.... that may be true for 9x also, I don't remember. Either way, it
seems fairly simple to search for something consistent in the 'dir'
output for a directory containing no files.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
Dean Wells said:
Not having a 98 boot disk or installed copy easily to hand, I can't
test anything but in your shoes I would probably try precisely the
tools you mentioned also searching on the number of files. Simply
test the errorlevel resulting from the search and proceed
accordingly.

Searching for "file not found will only tell you that the file you
were looking for was not there. What I think you want to know is:
does this folder contain ANY files or ANY subfolders.

You *could* do something like this:

set cfd=c
dir/s/a folder\*.* | find " 0 File(s) "
if errorlevel 1 set cfd=%cfd%f
dir/s/a folder\*.* | find " 2 Dir(s) "
if errorlevel 1 set cfd=%cfd%d

if "%cfd%"=="c" goto:isempty

echo/directory "folder" is NOT empty

I do not have 9x running either, and am basing the search strings on
what shows up when the dir/s/a command is run against an empty folder
on XP. But even on XP this will fail should there be files and/or
folders whose names contain the search strings.

/Al
--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
how can I tell if a folder or drive is empty via a dos batch file
(no wsh support for this)? It needs to be part of a batch file run
from a win98 boot disk. I need to test for this condition and take
action only if the drive is empty.

any ideas?

I think I could use the 'dir' and 'find' commands to do this by
testing for 'file not found' but I was wondering if there was a more
direct or better approach than that.

anyone?

thanks in advance.
 
thanks for the input!

Dean Wells said:
... that may be true for 9x also, I don't remember. Either way, it
seems fairly simple to search for something consistent in the 'dir'
output for a directory containing no files.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
Dean Wells said:
Not having a 98 boot disk or installed copy easily to hand, I can't
test anything but in your shoes I would probably try precisely the
tools you mentioned also searching on the number of files. Simply
test the errorlevel resulting from the search and proceed
accordingly.

Searching for "file not found will only tell you that the file you
were looking for was not there. What I think you want to know is:
does this folder contain ANY files or ANY subfolders.

You *could* do something like this:

set cfd=c
dir/s/a folder\*.* | find " 0 File(s) "
if errorlevel 1 set cfd=%cfd%f
dir/s/a folder\*.* | find " 2 Dir(s) "
if errorlevel 1 set cfd=%cfd%d

if "%cfd%"=="c" goto:isempty

echo/directory "folder" is NOT empty

I do not have 9x running either, and am basing the search strings on
what shows up when the dir/s/a command is run against an empty folder
on XP. But even on XP this will fail should there be files and/or
folders whose names contain the search strings.

/Al
--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

djc wrote:
how can I tell if a folder or drive is empty via a dos batch file
(no wsh support for this)? It needs to be part of a batch file run
from a win98 boot disk. I need to test for this condition and take
action only if the drive is empty.

any ideas?

I think I could use the 'dir' and 'find' commands to do this by
testing for 'file not found' but I was wondering if there was a more
direct or better approach than that.

anyone?

thanks in advance.
 
thanks for the input!

Al Dunbar said:
Dean Wells said:
Not having a 98 boot disk or installed copy easily to hand, I can't test
anything but in your shoes I would probably try precisely the tools you
mentioned also searching on the number of files. Simply test the
errorlevel resulting from the search and proceed accordingly.

Searching for "file not found will only tell you that the file you were
looking for was not there. What I think you want to know is: does this
folder contain ANY files or ANY subfolders.

You *could* do something like this:

set cfd=c
dir/s/a folder\*.* | find " 0 File(s) "
if errorlevel 1 set cfd=%cfd%f
dir/s/a folder\*.* | find " 2 Dir(s) "
if errorlevel 1 set cfd=%cfd%d

if "%cfd%"=="c" goto:isempty

echo/directory "folder" is NOT empty

I do not have 9x running either, and am basing the search strings on what
shows up when the dir/s/a command is run against an empty folder on XP. But
even on XP this will fail should there be files and/or folders whose names
contain the search strings.

/Al
--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l
how can I tell if a folder or drive is empty via a dos batch file (no
wsh support for this)? It needs to be part of a batch file run from a
win98 boot disk. I need to test for this condition and take action
only if the drive is empty.

any ideas?

I think I could use the 'dir' and 'find' commands to do this by
testing for 'file not found' but I was wondering if there was a more
direct or better approach than that.

anyone?

thanks in advance.
 
Back
Top