1.

Solve : Testing Dir for NO Files?

Answer»

I have done a review and search of you system and I can't find an answer that way.  So I will toss out this question to you all myself.

Utilizing XP Professional (and possible Home version) DOS

I need to test the subdir to see if there are any files placed in it.  If a file is there, then it would get moved out or zipped up and deleted out of the subdir.  But if there is no file in the subdir then the routine would move onto the next task.

ie

if not exist C:\users\Netbak\*.* goto Skip
move C:\users\Netbak\*.* C:\users\SaveToZip

I have found when the subdir is empty that I then get an error
1st the routine does not goto Skip
So it ends up doing the next line that should have been skipped
Then I get the move error, that there are no files to move
     The filename, directory name, or volume label syntax is incorrect.
Might be easier to SPECIFY each file individually instead of using wildcards.

Code: [SELECT]echo off
for /f "tokens=* delims=" %%i in ('dir /b /s C:\users\Netbak') do (
    move "%%i" C:\users\SaveToZip
)

The code will loop as many times as there are files, including zero times.

 8-)
I have to use wildcards because I don't really know what type of files I might find in a couple of the dirs that I have to work with.

Your suggestion worked very nicely in my test program.  I will incorporate it in the main program and see what happens.  

Thank You Very MUCH!!!Further testing reviels the basically same problem.

So I will try to expound on the problem (simplistically).

The routine first goes thru the hard drive various sub dirs to clean out old files to be zipped up into temp archive files. (After a month we have found that if you have not needed the files yet, you are not going to need them because of newer simular files.)
Anyhow, if the routine doesn't find any files in any of the subdirs. It still gets an error when it trys to zip up the dir where all the files should be placed but is found to be empty.

So I still have a need to test a dir to see if it has anything in it or if it is empty.

The following code;
          if not exist C:\users\Temp\*.* goto b5
  will only test test true if the dir does NOT exist
  will test false if the dir DOES exist, empty or not
Which is where my problem is!
The dirs exist, I need to test if they are empty or not.

The suggested routine works with the need to move the files, existing or not, without erroring.  But I still need to test for the zipping routine, to avoid the error.

Am I looking at this wrong? Or with tunnel vision?

Waiting for help.I am running in to the exact same problem. Have you got a fix or work around yet?There are probably other ways to do this, but counting the NUMBER of files moved to the zip directory seems simple enough.

Code: [Select]echo off
for /f "tokens=* delims=" %%i in ('dir /b /s C:\users\Netbak') do (
    move "%%i" C:\users\SaveToZip
    call set /a count=%%count%%+1
)
if %count% GTR 0  ...zip routine goes here

Not for nothing, but I don't see any logic for aging the files.

 8-)

On a XP machine I would suggest using Windows Script (VBSCRIPT)

To test for a dir existing: if exist C:\users\SaveToZip\nul should work.To check FOLDER and sub-folders for existing files try:

dir /b /s /a-d C:\users\Netbak 2>NUL&&echo.Files exist
or
dir /b /s /a-d C:\users\Netbak 2>NUL||echo.No Files

Note if you have sub-folders but no files it returns "No Files".
Hope this helps



Discussion

No Comment Found