Created
January 9, 2022 23:33
-
-
Save bengalih/8e5d0d2f49f913539def7376165708c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| F:\>python | |
| Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32 | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> from FATtools.Volume import * | |
| >>> root = vopen('F:', 'r+b') | |
| >>> root.listdir() | |
| ['MP3S', 'System Volume Information', 'C.mp3', 'B.mp3', 'A.mp3'] | |
| >>> root.sort() | |
| (7, 121) | |
| >>> root.listdir() | |
| ['MP3S', 'System Volume Information', 'C.mp3', 'B.mp3', 'A.mp3'] | |
| >>> root.flush() | |
| >>> root.listdir() | |
| ['MP3S', 'System Volume Information', 'C.mp3', 'B.mp3', 'A.mp3'] | |
| >>> root.close() | |
| Traceback (most recent call last): | |
| File "<stdin>", line 1, in <module> | |
| TypeError: close() missing 1 required positional argument: 'handle' |
Author
Thanks.
In fact, "closing while running" is not so easy nor a quick fix - perhaps Dirtable.flush() could suit to your needs, but it probably will conflict (in a dangerous, destructive way...?) with some atexit.registered functions.
Perhaps one day I'll introduce some sort of Volume.vclose() that carry on the magic...
Hint: if ID3 library or something needs only to read data, and you can pass them as bytes, FATtools can open and read from files, before and after sorting.
Hello, my latest code should allow you to perform the requested operations in "mixed mode".
Author
@maxpat78 Just tested the following:
Type "help", "copyright", "credits" or "license" for more information.
>>> from FATtools.Volume import *
>>> root = vopen('H:', 'r+b')
>>> root.listdir()
['MP3S', 'System Volume Information', 'C.mp3', 'B.mp3', 'A.mp3']
>>> root.sort()
(7, 121)
>>> root.listdir()
['A.mp3', 'B.mp3', 'C.mp3', 'MP3S', 'System Volume Information']
>>> vclose(root)
I was successfully able to access the drive by letter from within the OS after issuing the vclose, so it appears to function for me.
Thanks very much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@maxpat78 Thanks for the clarification. I just wanted to make sure that I wasn't missing something and that once I opened the volume for sorting with FATTools that I would no longer be able to access the volume through any other means until the python code exited.
I am not very experienced with Python but hadn't encountered something like this before.
The code I am working on has to do the following:
I supposed I could move everything after 1 to before 1 if I first read the file list in normally, sort them in memory and do all the other steps before actually using FATTools to open the volume and sort on disk. It is just that I would not have thought to do it this way if I could read them in first in the correct order after sorting on disk (a necessary step anyway so would be less code to write).
So, if I understand you correctly while FATtools has some options like cp, ls, rm on a low level, my ability to use another library to access say, ID3 tags on these files would be much more complex (if not impossible) to do once I open the Volume with FATtools.
I would love to do your option #3, and perhaps when my Python skill gets closer to approaching yours I might have the ability to do so.
In the meantime, I will work on either thinking on refactoring the order of my proposed code, or go with my original option of nested scripts.
Thanks for your assistance and your work in developing these tools. Hopefully they will work out for my needs when all is said and done.