首页 > 解决方案 > R 创建带有日期和版本号的子文件夹(如果不存在)并增加版本号(如果存在)

问题描述

我目前正在编写一段代码,用于创建一个带有当前日期和版本号的子文件夹(即 20210603.0)。如果文件夹已经存在,我需要增加版本号,直到它到达当前日期和版本组合不存在的子文件夹(即如果 20210603.0 和 20210603.1 已经存在,那么我需要创建一个子文件夹“20210603.2) .我已经写了以下代码,但是如果当前日期的一个(或多个版本)已经存在,我不确定如何循环并通过增加版本号来创建一个新的子文件夹.我该怎么写第二部分?

main_dir<-"some_path"
sub_dir<-paste0(format(Sys.time(),'%Y%m%d.'), 0)

if (!dir.exists(file.path(main_dir, sub_dir))) {
  dir.create(file.path(main_dir, sub_dir))
} else {
#code to increment version number until a date/version number combination is found to not 
#exist and then create folder labeled with the date/version number combination
}

标签: r

解决方案


推荐阅读