This file contains 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
import os | |
import pathlib | |
# 1 | |
# ------------------------------------------------- | |
os.environ["ALLUSERSPROFILE"] | |
# The environment variable "ALLUSERSPROFILE" is available on Windows only. | |
# On Windows returns | |
# 'C:\\ProgramData' |
This file contains 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
import fnmatch | |
pattern = "aaa_*" # Special characters '*' and '?' | |
list_of_all_files = ['aaa_1.json', 'a.json', 'b.json'] | |
for filename in list_of_all_files: | |
if fnmatch.fnmatch(filename, pattern): | |
print(filename) |
This file contains 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
# See | |
# https://stackoverflow.com/questions/8384737/extract-file-name-from-path-no-matter-what-the-os-path-format | |
import ntpath | |
path_to_file = r"C:\a\b\s\d\f_a\aasdas_o_g.json" | |
print(ntpath.basename(path_to_file) | |
# Output: |
This file contains 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
# See | |
# https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory | |
from os import listdir | |
from os.path import isfile, join | |
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] |
This file contains 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
import pendulum | |
now = pendulum.now() | |
now.format('YYYYMMDD_HHmm') |
NewerOlder