[R] finding files whose name does NOT contain a given charac
(Ted Harding)
Ted.Harding at manchester.ac.uk
Tue Feb 2 16:41:57 CET 2010
On 02-Feb-10 15:18:28, Peter Dalgaard wrote:
> mauede at alice.it wrote:
>> Unluckily I dela with miRNA files whose name may contain the
>> character "*".
>> Because of the special meaning of "*" I have to remove it.
>> I found out how to make list.files() extract only those file
>> names which contain a "*"
>> Namely:
>> # list.files(pattern="\\*")
>>
>> Now I have to process all files whose name does NOT contain the
>> character "*".
>> I cannot have list.files() extract all files whose name does NOT
>> match pattern="\\*
>> I tried using "^" in such a pattern but nothing is returned.
>> Any suggestion is welcome.
>
> That'll be something like pattern="^[^*]*$" (untested, I don't think I
> have any filenames with "*" inside...)
>
> Alternatively, you might try
>
> allfiles <- list.files()
> withstar <- allfiles[grepl("\\*", allfiles)]
> nostar <- allfiles[!grepl("\\*", allfiles)]
Peter's first suggestion works. As often with regeular expressions,
"[...]" is your friend!
I have created dummy files "abcde" "pq*st" "uvwxyz", and then
list.files()
# [1] "abcde" "pq*st" "uvwxyz"
list.files(pattern="[*]")
# [1] "pq*st"
list.files(pattern="^[^*]*$")
# [1] "abcde" "uvwxyz"
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 02-Feb-10 Time: 15:41:53
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list