I have a folder with a LANDSAT image with 8 tif files.
list.files("C:/Users/Documents/04.HUMEDALES/L5__002072-09MAY-2006", pattern = glob2rx("*.TIF"),full.names = TRUE)
As is shown:
[1] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B1.TIF"
[2] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B2.TIF"
[3] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B3.TIF"
[4] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B4.TIF"
[5] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B5.TIF"
[6] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B6.TIF"
[7] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_B7.TIF"
[8] "C:/Users/Documents/L5__002072-09MAY-2006/LT05_L1TP_002072_20060509_20161121_01_T1_BQA.TIF"
How can I list only the tif files of the bands 1 to 5 and 7? I can´t find the right pattern. This is the closest I get (which only remove the last file: BQA.tif)
list.files("C:/Users/Documents/04.HUMEDALES/L5__002072-09MAY-2006", pattern = glob2rx("*B?.TIF"), full.names = TRUE)
From this set of files:
> list.files(".")
[1] "bar-foo_B1.tif" "bar-foo_B2.tif" "bar-foo_B3.tif" "bar-foo_B4.tif"
[5] "bar-foo_B5.tif" "bar-foo_B6.tif" "bar-foo_B7.tif" "bar-foo_BQA.tif"
[9] "foo_B1.tif" "foo_B2.tif" "foo_B3.tif" "foo_B4.tif"
[13] "foo_B5.tif" "foo_B6.tif" "foo_B7.tif" "foo_BQA.tif"
I can select using this regex which matches anything (.*), B, 1 to 5 and 7, then ".tif" and then the end of the file name:
> list.files(".",pattern=".*B[123457]\\.tif$", ignore.case=TRUE)
[1] "bar-foo_B1.tif" "bar-foo_B2.tif" "bar-foo_B3.tif" "bar-foo_B4.tif"
[5] "bar-foo_B5.tif" "bar-foo_B7.tif" "foo_B1.tif" "foo_B2.tif"
[9] "foo_B3.tif" "foo_B4.tif" "foo_B5.tif" "foo_B7.tif"