-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now use tempfile library to create temporary directory
- Loading branch information
1 parent
ec5421d
commit 621c1e2
Showing
2 changed files
with
14 additions
and
14 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import platform | ||
import os | ||
import tempfile | ||
import shutil | ||
|
||
def create_temp_folder(sub_directory): | ||
if platform.system() == 'Linux': | ||
path = '/tmp/%s' % sub_directory | ||
elif platform.system() == 'Windows': | ||
localappdata_path = os.getenv("LOCALAPPDATA") | ||
path = r'%s\Temp\%s' % (localappdata_path, sub_directory) | ||
else: | ||
raise ValueError('Method not implemented for this OS.') | ||
def create_temp_folder(sub_directory_name: str, delete_existing_files: bool): | ||
scratch_dir_name = tempfile.TemporaryDirectory().name | ||
dirpath = os.path.dirname(scratch_dir_name) | ||
temp_dir = os.path.join(dirpath, sub_directory_name) | ||
|
||
if os.path.isdir(path) == False: | ||
os.makedirs(path) | ||
|
||
return path | ||
if os.path.isdir(temp_dir) is False: | ||
os.makedirs(temp_dir) | ||
elif delete_existing_files is True: | ||
shutil.rmtree(temp_dir) | ||
os.makedirs(temp_dir) | ||
|
||
return temp_dir |