Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If a sub-folder is empty or not 1

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
523
Brasil
Hello dear collegues!

The current folder is RECEITAS and inside it I have a sub-folder called INFONUTR (this sub-folder has 65 files).

I run the command:
? Adir(INFONUTR)

and it shows 485

Indeed I just want to know if the sub-folder INFONUTR is empty or is not empty.


Thank you,
SitesMasstec
 
Dear SitesMasstec,

you use ADIR wrong. the first parameter of ADIR is the name of the array where the function places the directory content. the second parameter should be the name of the directory you want to check, possibly with full path.
something like this:
?ADIR(laDirArray,"c:\full\path\to\infonutr\*.*")
if the directory in question is empty, ADIR returns 0.
 
When you talk about an empty folder, be careful. A folder may contain sub-folders, files, both or neither. ADIR() will give different results depending on that combination.

In particular, if you just pass, for example, "c:\data\*.*" as the second parameter, you will get 0 if the folder contains no files, even though it might contain sub-folders. If you just pass "c:\data\", you will always get 0.

If the folder contains sub-folders, and you pass "c:\data\*.*" as the second parameter and "D" as the third parameter, you will get the total number of files and sub-folders, plus 2. The extra two are for the folder itself and its parent folder (as represented by [tt].[/tt] and [tt]..[/tt] in a DIR listing). If you pass "c:\data\" and "D", you will always get exactly 2.

None of this should be a problem provided you understand exactly what you are looking for when you are dealing with an empty folder.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you're only interested in file count 0, I'd check with SYS(2000,"*.*") after you CD into the folder. In case of a folder populated with files, no matter how many files are in there, this only fetches the name of the first one or returns the empty string. Especially when you know the folders you test have no subfolders (for example if it's temp folders you create and populate with temp files but not further levels of temp subfolders) that could also be sufficient to test and will be faster in case ADIR would create a lengthy array. ADIR always creates an array of file names, also with "D" you get files and directories and not just directories.

Bye, Olaf.



Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top