title: writeOGR saving for multiple shapefiles
body: <p>I'd like to use writeOGR inside a loop to save shapefiles to folders. I'm having trouble figuring out how the name is used to save the actual file.</p>
  
  <p>Say you've got this code:</p>
  
  <pre><code>require(sp)
  require(rgdal)
  
  for (i in listafiles){
  ffile &lt;-read.csv(i)    #reads file
  ###do some stuff on the file and obtain a polygon sp_poly
  
  sp_poly &lt;- SpatialPolygons(list(Polygons(list(Polygon(coords)), ID=1)))
  sp_poly_df &lt;- SpatialPolygonsDataFrame(sp_poly, data=data.frame(ID=1))
  ##here comes the problem
  writeOGR(sp_poly_df, dsn, layer, driver="ESRI Shapefile")
  
  }
  </code></pre>
  
  <p>I'd like writeOGR to save each resulting shapefile in a separate folder, with the name of the file. E.g., when 'i' is 'school17.csv', writeOGR would create subfolder .\school17\ and the 3 shapefiles be named: (school17.dbf | school17.shp | school17.shx)</p>
  
  <p>I can't figure out how the dsn and layer parameters work. </p>
  
  <p>Thanks in advance,      dev</p>