使用 R 列出具有指定扩展名的所有文件 [英] Using R to list all files with a specified extension

查看:68
本文介绍了使用 R 列出具有指定扩展名的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 R 非常陌生,正在更新 R 脚本以遍历使用 ArcGIS 创建的一系列 .dbf 表并生成一系列图表.

I'm very new to R and am working on updating an R script to iterate through a series of .dbf tables created using ArcGIS and produce a series of graphs.

我有一个目录 C:\Scratch,它将包含我所有的 .dbf 文件.但是,当 ArcGIS 创建这些表时,它还包含一个 .dbf.xml 文件.我想从我的文件列表和迭代中删除这些 .dbf.xml 文件.我试过搜索和试验正则表达式无济于事.这是我使用的基本表达式(不包括所有各种实验):

I have a directory, C:\Scratch, that will contain all of my .dbf files. However, when ArcGIS creates these tables, it also includes a .dbf.xml file. I want to remove these .dbf.xml files from my file list and thus my iteration. I've tried searching and experimenting with regular expressions to no avail. This is the basic expression I'm using (Excluding all of the various experimentation):

files <- list.files(pattern = "dbf")

谁能给我一些指导?

推荐答案

files <- list.files(pattern = "\\.dbf$")

$ 末尾表示这是字符串的结尾."dbf$" 也可以使用,但添加 \\. (. 是正则表达式中的特殊字符,因此您需要对其进行转义) 确保您只匹配扩展名为 .dbf 的文件(如果您有例如 .adbf 文件).

$ at the end means that this is end of string. "dbf$" will work too, but adding \\. (. is special character in regular expressions so you need to escape it) ensure that you match only files with extension .dbf (in case you have e.g. .adbf files).

这篇关于使用 R 列出具有指定扩展名的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆