目标:目前,我目录中的文件没有意义,我想将其重命名为描述性名称。
例如,当前名称是垃圾
#list starting directory for all the files
startingDir <- "AllComplete/"
filez <- list.files(startingDir, pattern=".pdb", full.names = FALSE)
head(filez)
[1] "0398602d83ba805a.final.pdb" "0b369239e1e4cb15.final.pdb"
[3] "0f94c3d3d2a1011b.final.pdb" "118e6d6e8a8015dd.final.pdb"
[5] "1ff3a129dd268754.final.pdb" "231175d58ba732a9.final.pdb”
...
[46] "f3f6bccf1fb6d2f6.final.pdb”
我想将文件重命名为名称字符串,其名称顺序相同,更有用。
具体来说,newName应满足以下条件:
[1] "ABI78961.1_cellulose_synthase_8_[Physcomitrella_patens]"
[2] "AAD20396.1_putative_cellulose_synthase_catalytic_subunit_[Arabidopsis_thaliana]"
[3] "ABI78958.1_cellulose_synthase_5_[Physcomitrella_patens]"
[4] "ADK77974.1_cellulose_synthase_A_[Griffithsia_monilis]"
[5] "AAM20487.1_cellulose_synthase-like_protein_[Arabidopsis_thaliana]”
...
[46] "ABP96902.1_cellulose_synthase_1_[Phytophthora_infestans]"
文件名和新名称在向量中的顺序相同
我尝试使用file.rename,但我认为我没有正确使用它。
# get the list of files names
startingDir <- "AllComplete/"
filez <- list.files(startingDir, pattern=".pdb", full.names = FALSE)
#create my string of new names that I want in the same order from a data frame containing that information
newNames <- my_data$`# Description`
#try to rename
file.rename(from=filez, to=newNames)
然后我得到了错误
cannot rename file '0398602d83ba805a.final.pdb' to 'ABI78961.1_cellulose_synthase_8_[Physcomitrella_patens]', reason 'No such file or directory’
我该如何解决这个问题?