tfatool icon indicating copy to clipboard operation
tfatool copied to clipboard

Nested directories sync

Open Atarity opened this issue 10 months ago • 5 comments

I found this place is the only to ask the question. I'm using tfatool and like it while I can't find a convenient way for realtime sync new pictures from camera to local dir. In basic example flashair-util -s -d /home/tad/Photos --only-jpg it watch default card dir which is /DCIM/100__TSB. My camera (Sony a5100) are not using that dir, Instead of that it creates time based named dirs (like /DCIM/10350218) for each session. AFAIK there is no way to change this behavior of a camera to force it store all pics in one dir.

Is there a way to watch whole /DCIM/ including all nested directories without pointing to exact one? Maybe it is possible to apply another type of filters except the exact directory?

Atarity avatar Feb 18 '25 10:02 Atarity

Hi @Atarity, good question. I can't work with my own project right now because I don't have a FlashAir device anymore. As I type this reply I'm ordering one to help people with issues like yours, so hopefully I can get this project into a better state soon.

Having said that, I'm looking at the source for flashair-util and I see that there is a -r/--remote-dir option. Have you tried using that? It defaults to "/DCIM/100__TSB" as you noticed but if you pass something else a new path should filter down to the functions that construct the requests to list files, delete them, upload them, and so on.

TadLeonard avatar Mar 10 '25 15:03 TadLeonard

You are right: I'm using it with option -r/--remote-dir now and it works. My only problem (which was not clearly explained in my initial message) is the camera created nested dirs based on it is own rules. It creates new dir by picture count, or by timer — idk. It can happen even during a shooting session. So for example tfatool watching for /DCIM/10350218 but it stop to sync pics because camera just created new dir under /DCIM and stores all new pictures there since now.

I normally run tfatool like this flashair-util -u http://flashair.local -s -d ~/Temp -r /DCIM/10350218 --only-jpg, but to do that I need to go to web UI first just to find full dir path camera using for storing pictures at a moment.

Atarity avatar Mar 11 '25 09:03 Atarity

I've just checked: as a workaround I can make .sh which will list all dirs under /DCIM first, then to pass the newest one as an argument for -r/--remote-dir.

flashair-util -u http://flashair.local -r /DCIM -l

Files in /DCIM

filename    date        time      MB  created
----------  ----------  ------  ----  ------------
101__TSB    1980-01-01  00:00      0  45 years ago
10050119    2025-01-19  00:01      0  a month ago
10250119    2025-01-19  00:58      0  a month ago
10350218    2025-02-18  00:30      0  3 weeks ago
10450218    2025-02-18  00:39      0  3 weeks ago
105MSDCF    2025-02-18  00:39      0  3 weeks ago
10650218    2025-02-18  12:14      0  2 weeks ago
10750307    2025-03-07  12:46      0  3 days ago

(8 files, 0.00 B total)

Atarity avatar Mar 11 '25 10:03 Atarity

Hmm, maybe I understand the issue now. My interpretation of what you're saying is that tfatool's (and FlashAir's) rudimentary approach doesn't help much when you point it at "/DCIM" because what you really need is an os.walk() kind of behavior. I think what should happen is that a command.list_files() should have a recursive: bool = False option so that it can optionally emit files and directories that are further down the tree. This would result in multiple requests each time you list files, but the way the sync code works it would only be using the command.memory_changed() (http://flashair/command.cgi?op=102) for each polling iteration.

TadLeonard avatar Mar 11 '25 23:03 TadLeonard

what you really need is an os.walk()

exactly.

For now I workaround the problem with smth like this:

flashair-util -u http://flashair.local -r /DCIM -l | awk '/^[0-9]{8}/ { print $1, $2, $3 }' | sort -k2,3r | head -n1 | awk '{ print $1 }' | xargs -I{} flashair-util -u http://flashair.local -s -d ~/Temp -r /DCIM/{} --only-jpg

Atarity avatar Mar 17 '25 11:03 Atarity