Python with win32com and EXIF renaming files. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python with win32com and EXIF renaming files. (/thread-33150.html) |
Python with win32com and EXIF renaming files. - Amrcodes - Apr-02-2021 Current behavior: blinking cursor Expected behavior: renaming media files. Steps I took to make this project 1. First I use pathlib to iterate for each file in the current folder. 2. Second I check if the file suffix on capital letters I convert it to small. 3. Third I check if the file suffix is '.m4v'. 4. Fourth If the file suffix is .m4v I use win32com to get the Media Creation date and time 5. Fifth I modify the date and time to fit the windows naming system. 6. Finally I use os.rename to rename any file that it's extension equal .m4v with the t value which is in fifth step. Everything works but renaming is not! printing the the original files name works. printing the media creation date using win32com works fine. printing random text before the renaming line works. printing random text after renaming line doesn't work. here is the code: ```py import os import pathlib from PIL import Image from PIL.ExifTags import TAGS # import datetime from win32com.propsys import propsys, pscon import time from datetime import datetime for p in pathlib.Path.cwd().iterdir(): ext = p.suffix tl = ext.lower() if p.suffix == '.m4v': vid = p.stem + p.suffix properties = propsys.SHGetPropertyStoreFromParsingName(str(p)) dt = properties.GetValue(pscon.PKEY_Media_DateEncoded).GetValue() t = datetime.strftime(dt, '%Y%m%d') print(dt) os.rename(vid , t + p.suffix) mov_name = p.stem ``` RE: Python with win32com and EXIF renaming files. - buran - Apr-02-2021 cross-posted on StackOverflow RE: Python with win32com and EXIF renaming files. - supuflounder - Apr-03-2021 You need to show the output and demonstrate what you mean by "random text", and indicate what was expected vs. what was shown. There is nothing in the code sample that helps analyze what is going on. RE: Python with win32com and EXIF renaming files. - Amrcodes - Apr-03-2021 (Apr-03-2021, 02:40 AM)supuflounder Wrote: You need to show the output and demonstrate what you mean by "random text", and indicate what was expected vs. what was shown. There is nothing in the code sample that helps analyze what is going on. I've already mentioned at the beginning of the post that the current behavior is a blinking cursor. So, the random text means a random string to test if the os.name works without the EXIF value. If you read the code you will find what should be the expected result, but it seems that you read it but not willing to understand. It's very basic code nothing is complex about it that may not be clear, but already I explained what is the steps I took to write this code and it's in the post. RE: Python with win32com and EXIF renaming files. - DeaD_EyE - Apr-03-2021 (Apr-02-2021, 07:01 PM)Amrcodes Wrote: os.rename(vid , t + p.suffix) I don't understand why you work with pathlib, if you still do the low-level-stuff by yourself. For example, Path has a rename method from the beginning on.The t + p.suffix is just a workaround because we had not the method with_stem . Since Python 3.9 it was introduced.vid = Path("/tmp/foo/bar/a_file.m4v") print(vid) new_file = vid.with_stem("2021-03-04T22:42:00") # with_stem was introduced with Python 3.9. print(new_file) vid.rename(new_file)We don't care about blinking cursors, we want input (which is your output). Run your code and show the output. If your code does not show output, use the print-function. If it fails, show also the whole traceback. The use of print(repr(some_object)) can clarify which kind of object this is.repr is a built-in function, which shows the representation of an object as str .
|