Constantly ran into some redundant works lately, like renaming folders/files, modifying file properties, etc. Hence, these mini tools.
Well, I'm no good at .bat
scripts. Which, doesn't require basically anything, and is much easier to use.
#Find all files in the folder
And files in sub-folder, sub-sub-folder,...
1 | def all_files_path(root_dir): |
The return value of the function above is a list of strings which contain the full path of the files under folder root_dir
.
With this function, there're so many stuff you get to do. For example, to delete all .un~
files under the current folder, simply pick all strings ending with '.py~'
, then use os.unlink
to delete corresponding files. With regular expressions, there're even more fun stuffs you can do.
#Deleting EXIF information
EXIF may contain a lot of sensitive information such as where and when the picture was taken, what kind of camera was used, plus even detailed parameters of a picture, ISO, aperture, etc. Therefore deleting EXIF information is widely suggested before uploading pictures to the internet or sending pictures to other people, even the people you know.
Below I'll use only .jpg
files to demonstrate how it's done.
1 | from pyexiv2 import Image |
{
"Exif.Image.Make": "Canon",
"Exif.Image.Model": "Canon EOS 800D",
"Exif.Image.Orientation": "1",
"Exif.Image.XResolution": "72/1",
"Exif.Image.YResolution": "72/1",
"Exif.Image.ResolutionUnit": "2",
"Exif.Image.DateTime": "2018:09:12 15:15:50",
...
}
Basically, EXIF is stored in the shape of a dictionary. Modifying all the values to whatever don't make any sense would just do the trick.
1 | from pyexiv2 import Image |
If you read the exif information now, it is gonna be like below.
{
"Exif.Image.Make": "",
"Exif.Image.Model": "",
"Exif.Image.Orientation": "",
"Exif.Image.XResolution": "",
"Exif.Image.YResolution": "",
"Exif.Image.ResolutionUnit": "",
"Exif.Image.DateTime": "",
...
}
#Open file with a certain application via console
Some times using console to start an application and open certain files would do a lot of benefit.
Here the script contains file renaming and processing all files under a perticular folder, combined with Find all files in the folder.
1 | if __name__ == "__main__": |
#Displace Curves with matplotlib
#Afterword
More yet to come. =.=