Greetings, R-ians: I'm using R 2.3.1 on WindowsXP. I need to find the name of a file at the end of a sting that contains the path + file, with the problematic "\\" as separators. The string looks something like this: "C:\\Documents and Settings\\myName\\My Documents\\R Projects\\Project1\\file.name.csv" What I want is "file.name.csv" Currently I use the name of the project as the splitter in strsplit(string.name, split="Project1", extended = FALSE) This works, of course, but I won't always be using folder Project1, so I need a more universal way to find the name of a file at the end of a string with "\\" separators. Can I get there from here? (I've looked through previous R-help listing of similar problems but if it's there, I missed it.) Thanks. Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com phone: 561-352-9699 eFax:? 614-455-3265 http://www.StatisticalEngineering.com ?
Try: basename(string.name) On 7/9/06, Charles Annis, P.E. <Charles.Annis at statisticalengineering.com> wrote:> Greetings, R-ians: > > I'm using R 2.3.1 on WindowsXP. > > I need to find the name of a file at the end of a sting that contains the > path + file, with the problematic "\\" as separators. > > The string looks something like this: > > "C:\\Documents and Settings\\myName\\My Documents\\R > Projects\\Project1\\file.name.csv" > > What I want is "file.name.csv" > > Currently I use the name of the project as the splitter in > > strsplit(string.name, split="Project1", extended = FALSE) > > This works, of course, but I won't always be using folder Project1, so I > need a more universal way to find the name of a file at the end of a string > with "\\" separators. > > Can I get there from here? (I've looked through previous R-help listing of > similar problems but if it's there, I missed it.) > > Thanks. > > > Charles Annis, P.E. > > Charles.Annis at StatisticalEngineering.com > phone: 561-352-9699 > eFax: 614-455-3265 > http://www.StatisticalEngineering.com > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
?basename On 7/9/06, Charles Annis, P.E. <Charles.Annis@statisticalengineering.com> wrote:> > Greetings, R-ians: > > I'm using R 2.3.1 on WindowsXP. > > I need to find the name of a file at the end of a sting that contains the > path + file, with the problematic "\\" as separators. > > The string looks something like this: > > "C:\\Documents and Settings\\myName\\My Documents\\R > Projects\\Project1\\file.name.csv" > > What I want is "file.name.csv" > > Currently I use the name of the project as the splitter in > > strsplit(string.name, split="Project1", extended = FALSE) > > This works, of course, but I won't always be using folder Project1, so I > need a more universal way to find the name of a file at the end of a > string > with "\\" separators. > > Can I get there from here? (I've looked through previous R-help listing > of > similar problems but if it's there, I missed it.) > > Thanks. > > > Charles Annis, P.E. > > Charles.Annis@StatisticalEngineering.com > phone: 561-352-9699 > eFax: 614-455-3265 > http://www.StatisticalEngineering.com > > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What is the problem you are trying to solve? [[alternative HTML version deleted]]
basename() works. If you're on a system that doesn't think \\ is a path separator, you could do something like x <- "C:\\Documents and Settings\\myName\\My Documents\\RProjects\\Project1\\file.name.csv" basename(gsub('\\\\','/',x)) Duncan Murdoch Charles Annis, P.E. wrote:> Greetings, R-ians: > > I'm using R 2.3.1 on WindowsXP. > > I need to find the name of a file at the end of a sting that contains the > path + file, with the problematic "\\" as separators. > > The string looks something like this: > > "C:\\Documents and Settings\\myName\\My Documents\\R > Projects\\Project1\\file.name.csv" > > What I want is "file.name.csv" > > Currently I use the name of the project as the splitter in > > strsplit(string.name, split="Project1", extended = FALSE) > > This works, of course, but I won't always be using folder Project1, so I > need a more universal way to find the name of a file at the end of a string > with "\\" separators. > > Can I get there from here? (I've looked through previous R-help listing of > similar problems but if it's there, I missed it.) > > Thanks. > > > Charles Annis, P.E. > > Charles.Annis at StatisticalEngineering.com > phone: 561-352-9699 > eFax: 614-455-3265 > http://www.StatisticalEngineering.com > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Moved to r-devel. Perhaps basename should take an optional separator argument so that basename(x, "\\") could be used to override the default behavior. On 7/9/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:> basename() works. If you're on a system that doesn't think \\ is a path > separator, you could do something like > > x <- "C:\\Documents and Settings\\myName\\My > Documents\\RProjects\\Project1\\file.name.csv" > basename(gsub('\\\\','/',x)) > > Duncan Murdoch > > Charles Annis, P.E. wrote: > > Greetings, R-ians: > > > > I'm using R 2.3.1 on WindowsXP. > > > > I need to find the name of a file at the end of a sting that contains the > > path + file, with the problematic "\\" as separators. > > > > The string looks something like this: > > > > "C:\\Documents and Settings\\myName\\My Documents\\R > > Projects\\Project1\\file.name.csv" > > > > What I want is "file.name.csv" > > > > Currently I use the name of the project as the splitter in > > > > strsplit(string.name, split="Project1", extended = FALSE) > > > > This works, of course, but I won't always be using folder Project1, so I > > need a more universal way to find the name of a file at the end of a string > > with "\\" separators. > > > > Can I get there from here? (I've looked through previous R-help listing of > > similar problems but if it's there, I missed it.) > > > > Thanks. > > > > > > Charles Annis, P.E. > > > > Charles.Annis at StatisticalEngineering.com > > phone: 561-352-9699 > > eFax: 614-455-3265 > > http://www.StatisticalEngineering.com > > > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >