/
ImportDriveFiles.py
35 lines (32 loc) · 1.2 KB
/
ImportDriveFiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 11/10/2020
import glob, os, shutil
from pathlib import Path
from os.path import abspath
from google.colab import drive
class ImportDriveFiles:
'''Import files to Colab Google Drive'''
def __init__(self):
# self.idf=None
self.contentPath='/content'
self.drivePath='/content/drive'
self.myDrivePath='/content/drive/My Drive'
self.pythonFilesPath='/content/drive/My Drive/PythonFiles'
self.importFileList=None
if os.path.exists(self.pythonFilesPath):
os.chdir(self.pythonFilesPath)
self.importFileList=glob.glob('*.py')
self.importFiles()
os.chdir(self.contentPath)
else:
print('path not exist\nMounting google drive')
drive.mount(self.drivePath, force_remount=True)
os.chdir(self.pythonFilesPath)
self.importFileList=glob.glob('*.py')
self.importFiles()
os.chdir(self.contentPath)
def importFiles(self):
for fil in sorted(self.importFileList):
sourcePath=abspath(fil)
destinationPath=os.path.join(self.contentPath, fil)
shutil.copy(sourcePath, destinationPath)
idf=ImportDriveFiles()