Hide hidden names from iterdir()
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))
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.
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
self.contents = [x for x in cur_path.iterdir() if not x startswith(".")]
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)...
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.
globis 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('**/[!.]*')