Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/b01fd37fcc018c7e6dd319241bee1489 to your computer and use it in GitHub Desktop.
Save jennyonjourney/b01fd37fcc018c7e6dd319241bee1489 to your computer and use it in GitHub Desktop.
Python - copyree_movetree + 외장함수os
import shutil
shutil.copy('../fff/Chicago.jpg','../mmm/image2.jpg')
#시카고 이미지를 mmm폴더의 imgage2로 저장하겠다.
shutil.move('../mmm/image2.jpg','../fff/Chicago2.jpg')
#mmm폴더의 image2를 다시 fff폴더에 Chicago2이름으로 이동
--------------------------------------------------------
# http://cafe.naver.com/jx007s
#외장함수 os를 가져다 써야 한다.
import os
print(os.getcwd()) #실행하고 있는 디렉토리를 알려준다.
print(os.path.exists('C:\\kyjeon\\study\\asdf')) #asdf라는 폴더가 있니? 없으면 false
print(os.path.exists('C:\\kyjeon\\study\\fff'))
print(os.path.isdir('C:\\kyjeon\\study\\fff')) #디렉토리니?
print(os.path.isfile('C:\\kyjeon\\study\\fff')) #파일이니?
print('----------------------------------')
ddd = os.listdir('C:\\kyjeon\\study\\fff')
print(ddd) #이 안에 있는 파일이나 폴더를 쭉 검사
for ff in ddd:
print(ff)
#movetree는 폴더대 폴더 이동, copytree는 폴더대 폴더 카피
print('--------------폴더 이동-----------------')
# txt, csv : txt 디렉토리에
# jpg,png,gif,bmp : img 디렉토리에
# 그 외는 : etc 디렉토리에 move하기
# shutil.move('../mmm/image2.jpg','../fff/Chicago2.jpg')
ddd = os.listdir('C:\\kyjeon\\study\\fff')
arr={
'txt':'txt',
'csv':'txt',
'jpg':'img',
'png':'img',
'gif':'img',
'bmp':'img'
}
import shutil
for ff in ddd:스
ext = ff[ff.rfind('.')+1:]
dst = 'etc'
if ext in arr:
dst=arr[ext]
shutil.copy('../fff/'+ff, '../ddd/'+dst+'/'+ff)
print(ff,ext,dst)
print('----------------------------------------')
#폴더에서 빈창에다가 shit누른채로 오른쪽 마우스>여기서 명령창열기
#ping www.google.com
#ping이라는 명령어는 호스트명이 들어오면, 그 호스트에 들어가서 실행하고 나온다
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment