Created
July 21, 2020 16:45
-
-
Save karmanyaahm/2a49f0007e362c68733889329f898f57 to your computer and use it in GitHub Desktop.
Python 3.8 file handling functions
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 | |
def getdirs(): | |
return [f.path for f in os.scandir('.') if f.is_dir()] | |
def delempty(dir): | |
for i in [f[0] for f in os.walk(dir) if os.path.isdir(f[0])]: | |
try: | |
os.rmdir(i) | |
except OSError: | |
pass | |
def getfiles(): | |
return [f.path for f in os.scandir('.') if f.is_file()] | |
# def rename(renamenum, filename, newname): | |
# i = filename | |
# j = newname + i[renamenum:] | |
# shutil.move(i, j) | |
# print(j) | |
# def rename_BorC(): | |
# files = glob.glob('*.zip') | |
# for thefile in files: | |
# thefile = os.path.basename(thefile) | |
# shutil.move(thefile, thefile[:-5]+'b.zip') | |
def getzips(inpdir='.'): | |
return [os.path.basename(f.path) for f in os.scandir(inpdir) if f.is_file() and os.path.basename(f.path).split('.')[1] == 'zip'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment