Thanks Romain, Uwe!
________________________________ From: Romain Francois <romain.franc...@dbmail.com> To: Uwe Ligges <lig...@statistik.tu-dortmund.de> Sent: Fri, December 11, 2009 5:35:57 AM Subject: Re: [R] copyING directories and files What about this as a start : dir.copy <- function( source = getwd(), target ){ files <- list.files( source, recursive = TRUE ) dirs <- unique( gsub( "/[^/]+$", "", files[grepl("/", files)] ) ) if( !file.exists( target ) ){ dir.create( target ) } for( d in dirs){ dir.create( file.path( target, d) , recursive = TRUE ) } for( f in files ){ file.copy( file.path(source, f) , file.path( target, f ) ) } invisible(NULL) } # what I am copying : > system( "tree" ) . âââ bar âââ blabla.txt âââ bla.txt âââ foobar âââ blabla.txt 2 directories, 3 files > dir.copy( getwd(), "/tmp/target" ) > system( "tree /tmp/target" ) /tmp/target âââ bar âââ blabla.txt âââ bla.txt âââ foobar âââ blabla.txt 2 directories, 3 files Romain On 12/11/2009 11:18 AM, Uwe Ligges wrote: > > I'd use a shell() command to call xcopy or robocopy, or cp given you > have some unix tools installed. > > Uwe Ligges > > > > Paul Evans wrote: >> Hi, >> >> I am using the windows version of R. I wanted to copy a directory >> (containing several files) to another directory. Is there any command >> in R that will let me do this (something like the 'cp' command in >> UNIX)? I have looked at 'file.copy', but as the name implies I think >> it only copies one file at a time. >> thanks! -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/Gq7i : ohloh |- http://tr.im/FtUu : new package : highlight `- http://tr.im/EAD5 : LondonR slides [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.