0

I want to save myself a lot of work and use Python to copy all the files with the .RAF extension from all of my external HD's directories and subdirectories to a folder on my MAC's desktop.

import os
import shutil

for root, dirs, files in os.walk("/Volumes/BCKP"):
    print(f"In directory {root}, we have files: {files}")
    for file in files:
        if file.endswith(".RAF"):
             path_file = os.path.join(root, file)
             shutil.copy2(path_file, os.path.expanduser("~/Desktop/pics"))
             print(f"Moving {file}")

However, when I run the code, only small portion of all the specified files are copied to the specified directory.

So for example in folder 2017.01.04 it only copies files from 2017.01.04/Pictures, completely skipping the 2017.01.04/RAW, where actually most of the .RAF files are, and then the program jumps to the next folder:

In directory /Volumes/BCKP/LRbckp/2017.01.04/Pictures, we have files: ['DSCF5741.RAF', 'DSCF5742.RAF', 'DSCF5743.RAF', 'DSCF5744.RAF', 'DSCF5749.RAF', 'DSCF5754.RAF', 'DSCF5757.RAF', 'DSCF5763.RAF', 'DSCF5768.JPG']
Moving DSCF5741.RAF
Moving DSCF5742.RAF
Moving DSCF5743.RAF
Moving DSCF5744.RAF
Moving DSCF5749.RAF
Moving DSCF5754.RAF
Moving DSCF5757.RAF
Moving DSCF5763.RAF
In directory /Volumes/BCKP/LRbckp/2017.04.07, we have files: ['2017.04.07-2.lrcat',

Please help me fix this, I am lost...

P.S. evidence that the folder exists: https://i.stack.imgur.com/fEhLp.jpg https://i.stack.imgur.com/3eZbx.jpg

Teo
  • 97
  • 1
  • 9
  • I see no evidence here that there is a `RAW` subdirectory. – Barmar Feb 16 '21 at 19:02
  • Here is the evidence: https://imgur.com/M2nZXF4 – Teo Feb 16 '21 at 19:03
  • Didn't you ask this identical question a little earlier? Why are you doing it again? – martineau Feb 16 '21 at 19:04
  • I added extra information – Teo Feb 16 '21 at 19:05
  • That's usually more appropriate for an edit, if there aren't any answers yet. That said -- what kind of filesystem is this? You can see this kind of misbehavior on filesystems where normal UNIX inode count semantics aren't followed. (It's not unique to Python; some `find` directives have similar optimizations where they assume that any subdirectory's `..` entry will increase the reference count for the parent directory). – Charles Duffy Feb 16 '21 at 19:11
  • _More_ helpful would be instructions that someone else could follow to create _their own_ directory structure that creates this bug. Even more helpful than that would be a script someone can run for the same purpose (remember, it still works for that purpose even if the files are empty, and even if there's no actual copying logic). And if in trying to build that reproducer you discover that you can't make it happen in your home directory, and that it _only_ happens on external media formatted a certain way, then you probably answered much of your own problem. – Charles Duffy Feb 16 '21 at 19:14
  • Sorry, I'm still new to this. The hard drive is NTFS, but I am on macOS – Teo Feb 16 '21 at 19:14
  • @CharlesDuffy Well, the python script I use is the first code that I shared. I guess I will have to get those .RAF files manually. I just wanted to use Python to make things easier on myself, but I guess there are no shortcuts in life... – Teo Feb 16 '21 at 19:17
  • BTW, which version of Python, specifically? `os.walk` has been through a few rewrites over the course of the Python 3 series. – Charles Duffy Feb 16 '21 at 19:17
  • @CharlesDuffy Python 3.9.1, as I understand Python 3.9 works with macOS M1 – Teo Feb 16 '21 at 19:19
  • So do older releases through Rosetta, but yes, that answers the question. – Charles Duffy Feb 16 '21 at 19:54
  • BTW, if you're just doing this to save time... I'd just use `rsync` for the job. `rsync -Prv --include='*..RAF' /Volumes/BCKP ~/Desktop/pics` and there you are. (Usage not precisely tested, you might need an `--exclude` to take out everything the `--include` doesn't match, but there's lots of Q&A going into the details; f/e, https://stackoverflow.com/questions/9952000/using-rsync-include-and-exclude-options-to-include-directory-and-file-by-pattern/9952100) – Charles Duffy Feb 16 '21 at 20:04

0 Answers0