I am trying to apply the same script to a few folders in the same directory. Separately the script works for each folder, but not when I use the following code:
 parent.folder <- "C:/R_Files/Data/DICOM"
    sub.folders <- list.dirs(parent.folder, recursive=TRUE)[-1]
    r.scripts <- file.path(parent.folder, "general_extract.r")
    # Run scripts in sub-folders 
    for(i in sub.foldes) {
      source(i)
    }
it shows me an error: Error in file(filename, "r", encoding = encoding) : cannot open the connection
The script is here:
DCM <- readDICOM()
mAs <- extractHeader(DCM$hdr, "Exposure", FALSE)
mat = matrix(data=mAs, ncol=1)
write.table(mat, file="curve.txt", row.names=FALSE, col.names=FALSE,quote=FALSE)
Is it possible to rewrite the script which will apply "general_extract.r" to each folder in main directory and create the txt file with the specific name, related to the subfolder's name?
 
     
    