Building a Python Library for returning basic file info (ongoing)
Things are going smoothly so far since working with strings and filenames are pretty straight forward in python 3.6
my github project so far:
https://github.com/jayyyin/python-filelib-thingy
going with the simplest task of extracting filename from a path in python comes with a built in module called os.path,really useful
getting the filesize of the file was a bit more tricky as it could be either an absolute path or relative path as it is more complicated I'll use a code snippet from my github
my github project so far:
https://github.com/jayyyin/python-filelib-thingy
going with the simplest task of extracting filename from a path in python comes with a built in module called os.path,really useful
getting the filesize of the file was a bit more tricky as it could be either an absolute path or relative path as it is more complicated I'll use a code snippet from my github
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
def getFileSize(pathName): | |
"""gets size of file, if it's an absolute path it'll find the file specifed otherwise it's a relative path and it will use a sub directory""" | |
if(os.path.isabs(pathName)): | |
return os.path.getsize(pathName) | |
else: | |
fn = os.path.join(os.path.dirname(__file__), pathName) | |
return os.path.getsize(fn) |
Comments
Post a Comment