Message-ID: <CAA5NU8oUUX8S5HwY5RD4rmycUdVKLwso_+G5GtAbioDrpXOaUQ@mail.gmail.com>
Date: 2020-04-24T14:07:44Z
From: Shubhasmita Sahani
Subject: Problem with loop in folders
Hi Everyone,
I am trying to loop through the folders in the major working directory.
Read the dbf file into the data frame then save the data frame as CSV file
in another folder.
For this, I have written this code, But not able to figure out where it is
going wrong. Any ideas will be of great support.
setwd(choose.dir())
csvpath= "C:/plan/Learning/dummydata/csv/"
a<-list.dirs()
inpath<-"C:/workplan/Q2/Project1"
for (folder in list.dirs()[-1]) {
path<-setwd(paste0("inpath",folder))
dbf<-list.files(path, pattern = "*ward.dbf")
df <- read.dbf(dbf)
dbfname<-basename(dbf)
name<-file_path_sans_ext(dbfname) # get the name of the file like
agra_ward
write.csv( df, file = paste0("csvpath",name,"csv"))
print(path)
}
--
Thanks & Regards,
Shubhasmita Sahani
[[alternative HTML version deleted]]