Saving image and then loading it in Swift (iOS)

This function will save an image in the documents folder: func saveImage(image: UIImage) -> Bool { guard let data = UIImageJPEGRepresentation(image, 1) ?? UIImagePNGRepresentation(image) else { return false } guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) as NSURL else { return false } do { try data.write(to: directory.appendingPathComponent(“fileName.png”)!) return … Read more

How to find files and skip directories in os.listdir

You need to filter out directories; os.listdir() lists all names in a given path. You can use os.path.isdir() for this: basepath=”/path/to/directory” for fname in os.listdir(basepath): path = os.path.join(basepath, fname) if os.path.isdir(path): # skip directories continue Note that this only filters out directories after following symlinks. fname is not necessarily a regular file, it could also … Read more