분류 전체보기48 fileBrowser.mel http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/ 2015. 6. 15. #004 : fileCopy&Move.py 파일 복사 및 이동 import shutil srcFile = '/home/Documents/python/src.src' dstFile = '/home/Documents/python/dst.dst' srcBackup = '/home/Documents/python/src.backup' shutil.copy(srcFile, dstFile) # create dst.dst shutil.copy(srcFile, srcBackup) # create src.backup shutil.move(srcFile, dstFile) # rewrite dst.dst and remove src.src shutil.copy('SRC', 'DST') SRC 경로의 파일을 DST 경로로 복사한다. (access time = 복사시점) .. 2015. 5. 8. #003 : fileContentsModification.py 파일 내용 변경하여 저장 (서로 다른 OS에서 case return, line feed가 다르게 설정되어 있어 Windows의 \r\n을 Linux의 \n으로 변경) import os path = open('/home/Documents/python/Alexa', 'r') lines = path.readlines() obj = open('Alexa.modified', 'w') # create Alexa.modified empty file in write mode for line in lines: newLine = line.replace('\r\n', '\n') obj.write(newLine) obj.close() open('FILE', 'r') FILE 파일을 연다. r: read mode w: writ.. 2015. 5. 8. #002 : printOutSortedFileList.py 숫자로만 이루어진 파일명을 갖고 있는 파일 5,000개를 다양한 조건으로 sorting하여 출력 1. 숫자 9로 시작하는 파일 리스트 및 개수 2. 숫자 7로 끝나는 파일 리스트 및 개수 3. 파일명에 172를 포함한 파일 리스트 및 개수 4. 파일명에 7을 최소 다섯 개 이상 포함한 파일 리스트 및 개수 5. 파일명의 각 자리수의 합이 70 이상인 파일 리스트 및 개수 import os target = '/home/Documents/python/files' fileList = os.listdir(target) ##### 1. count = 0 for i in fileList: if os.path.isfile(os.path.join(target,i)): if i.startwith('9'): print i.. 2015. 5. 8. 이전 1 2 3 4 5 6 7 8 ··· 12 다음