diff options
author | Owl <isaclien9752@gmail.com> | 2025-09-26 14:32:34 -0400 |
---|---|---|
committer | Owl <isaclien9752@gmail.com> | 2025-09-26 14:32:34 -0400 |
commit | 70e647076418d114111aa76b5d3639a5b4271e94 (patch) | |
tree | 2e67e3c523818c7628497ff2f6e9e5c9645814d2 /file_ops.py | |
parent | 45dc6171705fd074657b0ed5bde2502431b74c4b (diff) | |
download | blenxy-70e647076418d114111aa76b5d3639a5b4271e94.tar.gz blenxy-70e647076418d114111aa76b5d3639a5b4271e94.zip |
bcsv and other stuff
Diffstat (limited to 'file_ops.py')
-rw-r--r-- | file_ops.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/file_ops.py b/file_ops.py index bbad813..8c7178d 100644 --- a/file_ops.py +++ b/file_ops.py @@ -1,6 +1,6 @@ # my functions for file creation/deletion operations # also for file path string stuff -import os, shutil +import os, shutil, io # function to format a path string correctly: # - no duplicate slashes @@ -10,7 +10,7 @@ def get_path_str(path): # check params if (type(path) != str): - return "" + return None # else work on the string rtn_str = "" @@ -233,12 +233,19 @@ def rm_folder(path): return True # function to get the size of a file -def get_file_size(path): - - # check params - if (is_file(path) == False): - return 0 - return os.path.getsize(get_path_str(path)) +def get_file_size(path_or_stream): + # check params and get the size if the + # thing is a file or a stream object + if (type(path_or_stream) == str and is_file(path_or_stream) == True): + return os.path.getsize(get_path_str(path_or_stream)) + elif (type(path_or_stream) == io.BytesIO): + size = 0 + path_or_stream.seek(0) + while (path_or_stream.read(1) != b""): + size += 1 + path_or_stream.seek(0) + return size + return 0 # function to rename a folder or a file def rename(current_name, new_name): |