프로그래밍_기타
google colab, drive 연동, 파일 다루기
wjwkddyd221001
2022. 10. 1. 12:51
1. google drive mount
from google.colab import drive
drive.mount('/content/drive')
2. 타인의 google drive에서 파일 가져오기, 압축 해제하기
!pip install gdown
import gdown
import shutil
import zipfile
google_path = 'https://drive.google.com/uc?id='
file_id = ''
output_name = 'train.zip'
## 파일 다운로드
gdown.download(google_path + file_id, output_name, quiet=False)
## 파일을 ROOT_PATH로 이동
shutil.move("./" + output_name, ROOT_PATH)
## 파일 압축해제
with zipfile.ZipFile(ROOT_PATH + "/" + output_name) as z:
z.extractall(ROOT_PATH)
file_id의 경우: 다음과 같이 설정하면 된다
3. 파일 다운로드
from google.colab import files
file_path = ''
files.download(file_path)