列出具有多个条件的文件part2

列出具有多个条件的文件part2

本文介绍了列出具有多个条件的文件part2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有以下栅格并将其导入R中.我的文件现在称为:

I have the following rasters and would like to import them in R. My files are now called:

B02_10m.jp2
B03_10m.jp2
B04_10m.jp2
B08_10m.jp2

B05_20m.jp2
B06_20m.jp2
B07_20m.jp2
B8A_20m.jp2
B11_20m.jp2
B12_20m.jp2

它们位于不同的子文件夹中.我就是这样使用recursive=TRUE

They are located in different sub-folders. That's way I am using recursive=TRUE

我正在尝试使用以下选项来组合条件,但是它不起作用.

I have trying with the following options to combine the conditions but it's not working.

 S2 <- "my/path"
S2 <- list.files(S2, recursive = TRUE, full.names = TRUE, pattern =  "B0[2348]_10m.jp2$ | B(0[567]_20m)|(1[12]_20m)|(8A_20m).jp2$")

S2 <- "my/path"
S2 <- list.files(S2, recursive = TRUE, full.names = TRUE, pattern =  "B0[2348]_10m | B(0[567]_20m)|(1[12]_20m)|(8A_20m).jp2$")

推荐答案

对于其他用户,基于@docendo discimus答案,这里的想法是在列出文件时结合本例中的不同条件.我的条件基于字母B后面的数字,因此:

For other users and based on @docendo discimus answer, here is the idea to combine different conditions when listing files as in my case. My conditions are based on the numbers that are following the letter B so:

pattern="B( here we need to write the conditions).jp2$

首先,我们将设置条件以导入文件B02_10m,B03_10m,B04_10m,B08_10m

First, we will set the condition to import the files B02_10m, B03_10m, B04_10m, B08_10m

patter="B(FIRST CONDITION OR SECOND CONDITION).jp2$
pattern="B((0[2348]_10m)|SECOND CONDITION).jp2$

第二,我们将导入文件B05_20m,B06_20m,B07_20m,B8A_20m,B11_20m,B12_20m.在这种情况下,我们必须组合几个子条件,因为模式从例如02变为11、12和8A

Second, we will import the files B05_20m, B06_20m, B07_20m, B8A_20m, B11_20m, B12_20m. In this case, we have to combine several sub-conditions because the pattern changes from e.g.: 02 to 11, 12 and 8A

首先,我们编写5、6和7的代码

First we write the code for 5, 6 and 7

pattern="B((0[2348]_10m)|((0[567])_20m)).jp2$

然后我们添加11和12区的代码

Then we add the code for bands 11 and 12

pattern="B((0[2348]_10m)|((0[567])|(1[12])_20m)).jp2$

然后,输入8A的代码

pattern="B((0[2348]_10m)|(((0[567])|(1[12])|(8A))_20m)).jp2$

希望很清楚

这篇关于列出具有多个条件的文件part2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:24