Skip to content

list.files() find files beginning with a .

4 messages · syrvn, Uwe Ligges, Brian Ripley +1 more

#
Hello,

when I use list.files with recursive = TRUE and all.files = TRUE, R returns
a list of strings/paths.
I tried using grep to achieve that. However, the problem is that because of
the recursive list.files parameter,
for some files beginning with a . there is a path attached. I think it is
not as simple as it looks because all files
end with . something. .xlsx or .txt or .r...
		
files <- list.files("~", recursive = TRUE, all.files = TRUE)
files
/XXX/ZZZ/.R_history
/XXX/ZZZ/AAA/Script.r
/XXX/ZZZ/BBB/test.xlsx
/XXX/ZZZ/CCC/.xyz

files <- files[grep("^.*$", files)]

I want grep to return only the following to lines:

/XXX/ZZZ/.R_history
/XXX/ZZZ/CCC/.xyz

Any ideas on how to solve that issue?

Cheers
syrvn

--
View this message in context: http://r.789695.n4.nabble.com/list-files-find-files-beginning-with-a-tp4635773.html
Sent from the R help mailing list archive at Nabble.com.
#
On 08.07.2012 14:47, syrvn wrote:
You do not need grep, let list.files do all the stuff for you:

list.files("~", recursive = TRUE, all.files = TRUE, pattern="^\\.")

Best,
Uwe Ligges
#
On 08/07/2012 14:35, Uwe Ligges wrote:
Some people find the equivalent pattern = "^[.]" clearer to read.