 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
| View previous topic :: View next topic |
| Author |
Message |
brucebowler Guest
|
Posted: Wed Aug 03, 2011 3:53 pm Post subject: |
|
|
| I could be wrong (I have been in the past) but the Fortran Standard, to the best of my knowledge, is "directory and file system ignorant" (and IMHO it should be that way) |
|
| Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2625 Location: Sydney
|
Posted: Thu Aug 04, 2011 1:23 am Post subject: |
|
|
I prefer the FILES@ approach to determine if a directory exists, as if the directory does exists and you have rights to access it, then you will get at least 2 entries; "." and "..".
My approach to counting the number of files in a directory would exclude these 2 system entries.
A directory could have only sub-directories and no files, or no files of the type you want ( eg .txt files). What answer would you want in this case ?
I agree with Bruce that the Fortran Standard does not help in this case.
John |
|
| Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8283 Location: Salford, UK
|
Posted: Thu Aug 04, 2011 7:20 am Post subject: |
|
|
Here is some C code that can be compiled with SCC...
| Code: |
extern "C" int count_files_at(char *rootDirectory)
{
HANDLE hFind;
WIN32_FIND_DATA findFileData;
char temp[MAX_PATH], rootDirectoryPattern[MAX_PATH];
int count = 0;
if(strchr(rootDirectory, '*'))
{
strcpy(rootDirectoryPattern, rootDirectory);
}
else
{
if(rootDirectory[strlen(rootDirectory)-1] == '\\') rootDirectory[strlen(rootDirectory)-1] = '\0';
strcpy(rootDirectoryPattern, rootDirectory);
strcat(rootDirectoryPattern, "\\*");
}
hFind = FindFirstFile (rootDirectoryPattern, &findFileData);
if(hFind != INVALID_HANDLE_VALUE)
{
do
{
strncpy(temp, rootDirectory, strlen(rootDirectory));
temp[strlen(rootDirectory)] = '\\';
temp[strlen(rootDirectory)+1] = '\0';
strcat(temp, findFileData.cFileName);
if (strcmp(findFileData.cFileName, ".") != 0 && strcmp(findFileData.cFileName, "..") != 0)
{
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) ++count;
}
} while (FindNextFile (hFind, &findFileData) != 0);
}
FindClose(hFind);
return count;
}
|
|
|
| Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: Nürnberg, Germany
|
Posted: Thu Aug 04, 2011 1:43 pm Post subject: |
|
|
Paul, thanks for the C-code.
Regarding the call to SYSTEM. It works with Silverfrost FTN95. However, it is not found in the documentation. According to the documentation and comments in this thread CISSUE should be use. For my unterstanding the call to SYSTEM should not work. What is the truth on this? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|