8 Replies Latest reply on Mar 14, 2008 1:25 PM by Oliver Goldman

    Searching a root directory

    RobbieDL
      Can the getDirectoryListing or getDirectoryListingAsync work with a root directory? I'm working on a little project to detect the input of USB devices. I'm trying to read the contents of the USB device (in this current case it's native path is E:/), but neither getDirectoryListing or getDirectoryListingAsync seem to read the contents.

      Is there anyway to get the contents of a root directory? I'm using Javascript.

      Appreciate any feedback. Cheers.
        • 1. Re: Searching a root directory
          Oliver Goldman Adobe Employee
          Yes, you should be able to enumerate a directory such as e:\. Can you provide a small code sample illustrating the problem?

          thanks,
          Oliver Goldman | Adobe AIR Engineering

          • 2. Searching a root directory
            RobbieDL Level 1
            Thanks for getting back to me, Oliver.

            Here's a little snippet of code from what I've got so far.

            var list = usbDrive.getDirectoryListing();

            dirList = [];

            for (i = 0; i < list.length; i++)
            {
            dirList.push(list .nativePath);
            }

            "usbDrive" is a global variable that contains the native path to the root directory I'm looking to get the directory listing for, which is currently E:/.

            If I change usbDrive.getDirectoryListing() to another directory, such as My Documents, it works just fine. But doesn't seem to work here.
            • 3. Re: Searching a root directory
              Oliver Goldman Adobe Employee
              The getDirectoryListing() call will return an Array, not a File. You probably intended something along the lines of "list .nativePath" inside the for loop?

              Oliver Goldman | Adobe AIR Engineering

              • 4. Re: Searching a root directory
                Oliver Goldman Adobe Employee
                Ah, interesting--apparently the array subscript notation is getting clobbered by the forum system. So that'd be "list [ 0 ] . nativePath". (Let's hope that comes through with square brackets intact.)

                Anway, this works in our testing. How are you initializing usbDrive?

                Oliver Goldman | Adobe AIR Engineering

                • 5. Re: Searching a root directory
                  RobbieDL Level 1
                  I initially have two functions; one that grabs the root directories when the application is first ran and stores them in an array, and a second then runs every 5 seconds and grabs the root directories and stores them in array again, but this time checking the length to see if it's different. If it is, this function gets run:

                  function checkNewRootDirs() {
                  tempArray = [];
                  for(i=0; i < newRootDirsArray.length; i++) {
                  inArray = true;
                  for(z=0; z < originalRootDirsArray.length; z++) {
                  if(newRootDirsArray == originalRootDirsArray[z]) {
                  inArray = false; }

                  tempArray
                  = inArray; } }

                  for(m=0; m < tempArray.length; m++) {
                  if(tempArray[m] == true) {
                  usbDrive = newRootDirsArray[m]; } }

                  dirListed(); }

                  When alerted out, usbDrive does contain the corrent native path to the USB drive. dirListed then runs the code I posted above, but returns no results.

                  Thanks again Oliver for lending a hand, much appreciated.
                  • 6. Re: Searching a root directory
                    Oliver Goldman Adobe Employee
                    So try a simpler app and see what happens. Two lines will do:
                    usbDrive = new File( "e:\" );
                    trace( usbDrive.getDirectoryList());

                    Oliver Goldman | Adobe AIR Engineering

                    • 7. Re: Searching a root directory
                      RobbieDL Level 1
                      Ah yeah, that did the trick. Ran the code this code:

                      var usbDrive = new air.File("E:/");
                      alert(usbDrive);

                      and it alerted out the contents of E:/. I then went back to my original code, and did a quick IF statement to see if it was seeing how I originally was grabbing the root drive as a directory, and low and behold, it wasn't. But modifying the code above a little should do the trick.

                      Big thanks for the help Oliver, really do appreicate it. While I'm here, I do have a couple of general AIR questions. Firstly, I picked up the O'Reilly AIR handbook the other day, and was browsing through and noticed it mentioned a File.Upload function. But reading through the AIR reference guide, I don't see any mention of the File.Upload function. Has it been taken out since the book was written?

                      Secondly, I've had a quick look through, but couldn't see anything. Does AIR have a built in function that can grab the extension of a file?

                      Thanks again,
                      • 8. Re: Searching a root directory
                        Oliver Goldman Adobe Employee
                        There is a File.upload() method; it's inherited from the FileReference class.

                        To get a file's extension, use the File.extension property.

                        regards,
                        Oliver Goldman | Adobe AIR Engineering