Shop OBEX P1 Docs P2 Docs Learn Events
FAT32 object file enumeration question — Parallax Forums

FAT32 object file enumeration question

ke4pjwke4pjw Posts: 1,079
edited 2023-01-10 07:50 in PASM2/Spin2 (P2)

I am working with the FAT32 object by Kwabena and @Cluso99 and have ran into a challenge enumerating the root directory. I can change to that directory, but I cannot use the FAT32 listEntry method.

The documentation in the comments state that listEntry will use whatever the current directory is, but I have found that not to be the case. I have to pass the path I want to enumerate to it. It will not accept "/".

Any guidance would be appreciated.

--Terry

movedirectory(String("/"), String("/Backup"))

pub movedirectory(sourcedir,destdir)
     if \FS.changeDirectory(sourcedir) ' I can get past this
        debug("Can't change to ", zstr_(sourcedir)) 

     if \FS.listEntry(sourcedir)  ' This fails
         debug("Can't list directory ", zstr_(sourcedir))

PS- Error is "Expected An Entry", so I guess it does not know how to deal with somone passing it the root of the filesystem. Looks like there is special code to deal with that in changeDirectory.

Comments

  • I modified listEntry to be able to deal with "/".

    Problem solved.

    PUB listEntry(entryPathName) : result
    
    '' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    '' // Searches the file system for the specified entry in the path name. Wraps around "listEntries."
    '' //
    '' // Returns the specified entry's name and caches the entry's information for use by the listing methods.
    '' //
    '' // If an error occurs this method will abort and return a pointer to a string describing that error.
    '' //
    '' // If a file is open when this method is called that file will be closed.
    '' //
    '' // EntryPathName - A file system path string specifying the path of the entry to search for.
    '' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
      closeFile()
    
      if(lockFileSystem("R"))
        listUncache()
          if(rootWithSpace(entryPathName))
            result := string("/")
            currentWorkingDirectory := 0
          else
            result := evaluateName(evaluatePath(entryPathName, "R"))
        listCache()
    
      unlockFileSystem()
    
  • I think you mildly misunderstood the API. The "correct" way of enumerating the a directory is to change into it, do listEntries("W") and then do listEntries("N") until it returns null. Though looking at it, your hack does seem like it would work, too.

  • Yeah, I tried that. It didn't work. I had to explicitly call listEntry with the path of the working directory before it would enumerate the files by performing listEntries("N"). Dumb. Some of that dumb may have been me stumbling around in the dark without any examples too.

Sign In or Register to comment.