omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Hide hidden names from iterdir()

    Pythonista
    4
    6
    3491
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • eriknie
      eriknie last edited by

      I want to select files from a folder. I use the following code:

      from pathlib import Path
      self.contents = list(curPath.iterdir())
      f = self.contents[i]
      name = os.path.basename(os.path.splitext(f)[0])

      I have a folder with 66 items, self.contents has 66 items.
      Sometimes it contains the correct names, sometimes, there are names with a '.' in the name.
      perhaps it has to do with the mix of PathLib and OS.
      The strange thing is that is can be working without the '.' for longer time and then suddenly it inludes the '.' files.

      Any clue?

      Many thanks!

      mikael 1 Reply Last reply Reply Quote 0
      • eriknie
        eriknie last edited by

        Extra info:

        The files that I want to read are stored in iCloud, also the python script files.

        and for some reason when this happens, I cannot open my python file from pythonista (the iCloud location where I keep my python files is empty), the files do exist when using "Files" on my iPad, I can see the python files, when clicking on it, it will open Pythonista and runs fine

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by ccc

          self.contents = [x for x in cur_path.iterdir() if not x startswith(".")]

          1 Reply Last reply Reply Quote 0
          • eriknie
            eriknie last edited by

            Thanks ccc,
            The idea is great! it will not work in your form of coding as the return value contains a full path.
            With minor adjustments it can work.

            In my app I read .txt and .jpg files for displaying

            However It seems that the problem is the .jpg files. For some reason the are offloaded in iCloud. I got only '.xxxx.jpg' files (with the . ).
            After opening the folder with 'Files' the image files had a small cloud icon on top and after a few seconds they started to download from the cloud and that made everything working again.

            For some reason the iCloud off loaded the images and downloaded them after opening them with 'files'

            Perhaps someone knows why and how to prevent this (As I use this app on stage during a performance)...

            1 Reply Last reply Reply Quote 0
            • cvp
              cvp last edited by

              iOS iCloud file is only kept locally if you have a lot of free memory in your iDevice and if the file has been used in the last days, else the local copy is removed and when you need it, it will be downloaded.
              That's Pythonista independent.

              1 Reply Last reply Reply Quote 0
              • mikael
                mikael @eriknie last edited by mikael

                @eriknie, glob is your friend, except it can be slow, if that matters to you.

                For example, visible files in the current directory:

                from pathlib import Path
                
                p = Path.cwd()
                visible_files = p.glob('**/[!.]*')
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors