'crop multiple netcdf files at once and write them with the same name

I have about 69 netcdf files downloaded. I want to crop them to my country or to the extent of my country. I am able to crop by individual file using "sellonlatbox" function from the package "cmsafops". Below is how I do for the individual file.

sellonlatbox(var = "tmax", 
             infile = "F:/Shieffeld/MaximumTemperature/Observation/tmax_daily_1949-1949.nc", 
             outfile = "F:/Shieffeld/MaximumTemperature/Observation/Croppped/tmax_daily_1949-1949.nc", 
             lon1 = 88.05, lon2 = 92.25, 
             lat1 = 26.05, lat2 = 28.55, 
             overwrite = TRUE)

Since doing individually for 69 files will take sometime and is not an efficient way, I am looking for a help to crop them at once and save them individually with the same file names. In this regard, any help from you will be greatly appreciated and save my time a lot. Thank you so much for your help!

Stay safe!

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source