first commit
This commit is contained in:
parent
99ce0acafb
commit
8f6b6a34e7
73 changed files with 11656 additions and 0 deletions
50
hot3d_processing/utils/file_systems.py
Normal file
50
hot3d_processing/utils/file_systems.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
|
||||
# remove a directory
|
||||
def remove_dir(dirName):
|
||||
if os.path.exists(dirName):
|
||||
shutil.rmtree(dirName)
|
||||
else:
|
||||
print("Invalid directory path!")
|
||||
|
||||
|
||||
# remake a directory
|
||||
def remake_dir(dirName):
|
||||
if os.path.exists(dirName):
|
||||
shutil.rmtree(dirName)
|
||||
os.makedirs(dirName)
|
||||
else:
|
||||
os.makedirs(dirName)
|
||||
|
||||
|
||||
# calculate the number of lines in a file
|
||||
def file_lines(fileName):
|
||||
if os.path.exists(fileName):
|
||||
with open(fileName, 'r') as fr:
|
||||
return len(fr.readlines())
|
||||
else:
|
||||
print("Invalid file path!")
|
||||
return 0
|
||||
|
||||
|
||||
# make a directory if it does not exist.
|
||||
def make_dir(dirName):
|
||||
if os.path.exists(dirName):
|
||||
print("Directory "+ dirName + " already exists.")
|
||||
else:
|
||||
os.makedirs(dirName)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
dirName = "test"
|
||||
RemakeDir(dirName)
|
||||
time.sleep(3)
|
||||
MakeDir(dirName)
|
||||
RemoveDir(dirName)
|
||||
time.sleep(3)
|
||||
MakeDir(dirName)
|
||||
#print(FileLines('233.txt'))
|
Loading…
Add table
Add a link
Reference in a new issue