R-在file.rename路径中使用通配符

R-在file.rename路径中使用通配符,r,R,我想不出这个的语法。我只想通过将“.sql.sql763286”替换为“.txt”来重命名以下内容: 我想要这个: C:/Documents and Settings/jdoe/Desktop/ealleip.sql.sql763286 将是: C:/Documents and Settings/jdoe/Desktop/ealleip.txt 我已经尝试了在Google、Rfunctions等网站上找到的各种语法。我甚至尝试了基本语法: file.rename ( 'C:/Document

我想不出这个的语法。我只想通过将“.sql.sql763286”替换为“.txt”来重命名以下内容:

我想要这个:

C:/Documents and Settings/jdoe/Desktop/ealleip.sql.sql763286
将是:

C:/Documents and Settings/jdoe/Desktop/ealleip.txt
我已经尝试了在Google、Rfunctions等网站上找到的各种语法。我甚至尝试了基本语法:

file.rename ( 'C:/Documents and Settings/jdoe/Desktop/ealleip*', 'C:/Documents and   Settings/jdoe/Desktop/ealleip.txt')
什么都不管用


有人能帮我吗?提前谢谢。

什么不起作用?错误消息是什么?感谢您的回复。我在一个有R“工具”的第三方软件中工作。它没有出错,只是没有重命名它。因此,当我尝试:file.rename('C:/Documents and Settings/jdoe/Desktop/ealleip.sql.sql7863286','C:/Documents and Settings/jdoe/Desktop/ealleip.txt')时,它可以正常工作,但当我用星号替换.sql.sql763286时,它不会出错,但它不会执行该功能不是R中的内置错误消息。我认为您不能在该函数中使用通配符。您可能想使用
dir
这个参数,它有一个与regexp兼容的
模式
参数,然后在上面使用
sub
来获得正确的输入以放入
文件。重命名
我已经尝试过文件。重命名('C:/Documents and Settings/mbarone/Desktop/+^[“ealleip”],'C:/Documents and Settings/mbarone/Desktop/ealleip.txt')。我没有得到一个错误,但它没有重命名文件。但是,如果我执行简单的file.rename('C:/Documents and Settings/mbarone/Desktop/ealeip.sql.sql763286','C:/Documents and Settings/mbarone/Desktop/ealleip.txt'),那么它会将其重命名。因此,我一定没有正确处理通配符。我尝试了^[“ealleip”]的几种不同变体,试图找出ealleip之后通配符的正确语法。
file.rename(from = paste0("C:/Documents and Settings/jdoe/Desktop/",list.files(path = "C:/Documents and Settings/jdoe/Desktop", pattern = "ealleip"), to = "C:/Documents and Settings/jdoe/Desktop/ealleip.txt")