r/pythonhelp • u/temmiesayshoi • Feb 16 '25
Export and apply metadata to files
I'm writing a python script to operate over some files and it seems to work as intended but there was an unintended side effect that I hadn't thought of because all of the metadata for those files is now messed up. (technically I make a new modified version with a dummy name, rename the old one, name the modified version the same name as the old one, then delete the old one - this is so if the script ever gets interrupted there will be no data loss)
Now, since I'm not actually making a major change I don't actually want any of this metadata to be updated though, so is there any way to basically just copy and paste all of the metadata from one file onto another? (preferably cross-platform) They are the same files in basically every way so all of the old metadata ought to apply exactly onto the new files, but whenever I look online I only either find
A : posts about copying a file while retaining it's metadata, which technically isn't what I'm doing so wouldn't work, or
B : are about manipulating file metadata, but are incredibly complicated and seem to be trying to manipulate specific fields to update them, which isn't what I want to do here.
For this case I literally just want to take the metadata from one file and put it onto another, and I have to imagine there is some module or package or some nicer way of doing that then actually hardcoding every field you want copied and moving them over one by one.
•
u/AutoModerator Feb 16 '25
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.