R에서 윈도우 폴더와 파일 다루기

2019. 6. 8. 22:10카테고리 없음

현재 작업 폴더 정보와 작업 폴더 지정

# get current working directory
getwd()
# set working directory
setwd("D:/r_study")

> getwd()
[1] "D:/r_study"
> # set working directory
> setwd("D:/r_study")

 

폴더 

dir.create("new_folder") # 폴더 생성
unlink('new_folder', recursive = T) # 폴더 제거

파일 다루기


file.create('hey.txt') # 파일 생성
file.remove('hey.txt') # 파일 제거

file.create(paste0('file',1:100,'txt')) # 연속 파일 생성
file.remove(paste0('file', 1:100, 'txt')) # 연속 파일 제거

file.copy('CALL_RENT_04MONTH.csv', 'new_folder') # 파일 복사

shell.exec('CALL_RENT_04MONTH.csv') # 파일 실행
file.show('CALL_RENT_04MONTH.csv') # 파일 실행

 

파일 정보


list.files()
list.files(recursive = T)
list.files(recursive = T, full.names = T) # 파일 리스트

ss = fileSnapshot() # 파일 스냅샷
> ss
File snapshot:
 path = D:\r_study
 timestamp = 
 file.info = TRUE
 md5sum = FALSE
 digest = NULL
 full.names = FALSE
 args = list()
 3 files recorded.

ss$info # 파일정보 
> ss$info
                         size isdir mode               mtime               ctime               atime exe
CALL_RENT_04MONTH.csv 3449348 FALSE  666 2019-06-08 11:25:36 2019-06-08 11:22:52 2019-06-08 11:25:35  no
r_schedule.log           2244 FALSE  666 2019-06-08 21:44:03 2019-06-08 21:23:00 2019-06-08 21:23:00  no
r_schedule.R              289 FALSE  666 2019-06-08 20:06:30 2019-06-08 20:06:30 2019-06-08 20:06:30  no

file.info('CALL_RENT_04MONTH.csv') # 파일 정보
> file.info('CALL_RENT_04MONTH.csv')
                         size isdir mode               mtime               ctime               atime exe
CALL_RENT_04MONTH.csv 3449348 FALSE  666 2019-06-08 11:25:36 2019-06-08 11:22:52 2019-06-08 11:25:35  no