2 Replies Latest reply on Oct 26, 2008 9:19 PM by Nadav_A

    random/unique file names in Air?

    Nadav_A
      Is there any way to generate unique file names in Air in a similar way to tempnam() (in python its os.tempnam() )?

      My code generates pictures and saves them to the desktop, and I wanted an easy way to generate unique file names (or "almost" unique..)

      Thanks
        • 1. Re: random/unique file names in Air?
          abeall Level 3
          You can use File.createTempFile() and File.createTempDirectory(), which will create a unique file in the system temporary file location. You can't use it to put a temp file on the desktop, though (nor should you be, really.)

          It sounds a bit like you need a unique name just to avoid overwrites, something like if "MyFile.jpg" already exists, automatically appends an incrementing number or the word "copy" or something, right?

          In that case I don't think there's any built in method, you have to come up with your own logic and implement it. I started to create a function to do this for my last project (ended up going a different direction) and it seemed pretty straight forward: just create a loop that keeps checking File.exists and break once you end up with a File that doesn't exist already.

          HTH
          • 2. Re: random/unique file names in Air?
            Nadav_A Level 1
            Thanks Aaron!
            The tempFile option seems like what I was looking for.
            I have a distributed application that takes many images and synchronizes them with many nodes, so I care more about not having to deal with multiple files with the same name than with overwriting :)

            Nadav