forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Testing for a directory
Goto page Previous  1, 2
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
brucebowler
Guest





PostPosted: Wed Aug 03, 2011 3:53 pm    Post subject: Reply with quote

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

PostPosted: Thu Aug 04, 2011 1:23 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8283
Location: Salford, UK

PostPosted: Thu Aug 04, 2011 7:20 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: Nürnberg, Germany

PostPosted: Thu Aug 04, 2011 1:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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