I have a folder called ntl which contains the following subfolders: beijing, cairo, delhi, la, mexico, rome, sydney. For example the path of the folders is C:\Users\nikos\OneDrive\Desktop\ntl\beijing, or C:\Users\nikos\OneDrive\Desktop\ntl\mexico and so on. Inside each subfolder there are many tif images named for example, t2013_01.tif, t2018_07.tif, t2023_12.tif etc. The name of the tif images means (for example the image t2023_12):
- t = time
- the next 4 strings are the year (2023)
- the 2 strings after the underscore is the month (12).
On a separate folder (outside the ntl folder) I have a folder called tst. Inside that folder I have the following subfolders: beijing, cairo, delhi, la, mexico, rome, sydney. For example the path of the folders is C:\Users\nikos\OneDrive\Desktop\tst\beijing, or C:\Users\nikos\OneDrive\Desktop\tst\delhi and so on. Inside each subfolder there are subsubfolders with the following names: 2013, 2014, 2015, ...., 2023. For example a path to these subsubfolders is: C:\Users\nikos\OneDrive\Desktop\tst\beijing\2013 or C:\Users\nikos\OneDrive\Desktop\tst\la\2022 and so on. Inside each subsubfolder there are 12 subfolders named: 01, 02, 03, ..., 12. For example a path is: C:\Users\nikos\OneDrive\Desktop\tst\beijing\2013\01, or C:\Users\nikos\OneDrive\Desktop\tst\beijing\2013\02, or C:\Users\nikos\OneDrive\Desktop\tst\beijing\2013\11 and so on.
My goal is to copy the tif images from the ntl/city folder and paste them to the tst/city/year/month folder depending on the date and time written in the name of the tif image. For example if I copy an image from the path C:\Users\nikos\OneDrive\Desktop\ntl\beijing\t2013_07.tif, this image should be pasted to the C:\Users\nikos\OneDrive\Desktop\tst\beijing\2013\07\t2017_07.tif path. Another example, if I copy an image from the path C:\Users\nikos\OneDrive\Desktop\ntl\rome\t2019_08.tif, this image should be pasted to the C:\Users\nikos\OneDrive\Desktop\tst\rome\2019\08\t2019_08.tif path.
More over, when I paste an image, I want to rename it to ntl.tif.
How can I do this in R? I don't a code to share as my attempts were all wrong.
R 4.3.2, RStudio 2023.12.1 Build 402, Windows 11.
My thought process regarding this problem:
file.path()function. e.g.city_dir <- file.path("C:\Users\nikos\OneDrive\Desktop\ntl", city_name)city_files <- list.files(city_dir)city_filesbased on its separator value. Usingstrsplit(city_files[i], split = '_')could work in a separate for-loop.Each of these steps are relatively simple and you can figure it out with a simple google query. Good luck!