Your list.of.files variable just has filenames without the fromFolder path. Try
file.copy(file.path,fromFolder,list.of.files), toFolder) --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On November 14, 2014 4:07:27 AM PST, "Muhuri, Pradip (SAMHSA/CBHSQ)" <pradip.muh...@samhsa.hhs.gov> wrote: >Hello, > >Here is something (file.copy) trivial but does not seem to work. I >could not figure out what I am doing wrong. > >The R script below creates folders (fromFolder and toFolder) and finds >the list of files (list.of.files) to be copied to the toFolder, which I >have verified using the print () command. But, the issue is that the >file.copy() command does not work. > >Both the R.script and the console are shown below. > >Any help/hints will be appreciated. > >Thanks, > >Pradip Muhuri > >######################### R script >##################################################### >#file.copy.R > >#identify the folders >fromFolder <- "H:/R/cis_study" >toFolder <- "F:/cis_study_backup" > ># find the list of files to copy >list.of.files <- list.files(fromFolder, ".R$") > ># print objects >print(c(fromFolder, toFolder, list.of.files)) >options(warn=1) > ># copy the files to the toFolder - THIS DOES NOT WORK WHILE EVERYTHING >PRIOR HAS WORKED >file.copy(list.of.files, toFolder) > > > >##################### Below is from console ################### >#file.copy.R >> >> #identify the folders >> fromFolder <- "H:/R/cis_study" >> toFolder <- "F:/cis_study_backup" >> >> # find the list of files to copy >> list.of.files <- list.files(fromFolder, ".R$") >> >> # print objects >> print(c(fromFolder, toFolder, list.of.files)) > [1] "H:/R/cis_study" "F:/cis_study_backup" > [3] "anl.in.scope_111114.R" "create.oid.data.frame.R" > [5] "create_xd2012.R" "file.copy.R" > [7] "further.data.R" "mrj.in.scope_111214.R" > [9] "oid.in.scope_111114.R" "oid_cohort.R" >[11] "warning.max.R" "xdate.R" >[13] "years.before.anl.init.R" "years.before.mrj.init.R" >[15] "years.before.oid.init.R" >> options(warn=1) >> >> # copy the files to the toFolder - THIS DOES NOT WORK WHILE >EVERYTHING PRIOR HAS WORKED >> file.copy(list.of.files, toFolder) >Warning in file.copy(list.of.files, toFolder) : >problem copying .\anl.in.scope_111114.R to >F:\cis_study_backup\anl.in.scope_111114.R: No such file or directory >(other similar warning messages are not shown) > > > >Pradip K. Muhuri, PhD >SAMHSA/CBHSQ >1 Choke Cherry Road, Room 2-1071 >Rockville, MD 20857 >Tel: 240-276-1070 >Fax: 240-276-1260 > >______________________________________________ >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. ______________________________________________ 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.