I have a folder which consist of subfolder which is shown in image

I want to copy files from this subfolder for example if subfolder name ends with 2020, it should copy all files from 01 Jan 2020 and 14 Jan 2020 and paste it to a new folder named ‘2020’.
Similarly it should done for 2021,2022,2023,2024 by creating separate folder for each year
Hi @ajnaraya
You can use for each file in folder to loop through all the folders
To get the year from the folder path
YearFolder = CurrentFolder.Name.Split(" "c).Last()
In If Condition this will check if folder is created with year or not
Directory.Exists(Path.Combine("YourFolderPath", YearFolder))
In Else Condition- It will create
Hope this helps ![]()
I dont need to move the subfolder, i just need to move files within the subfolder.
Example 1 Jan 2020 and 14 Jan 2020 has files inside it. I need to move files from that folder to ‘2020’ folder

Hi @ajnaraya
This will copy only the files inside the folders
Add for each file in a folder inside if condition & move file instead of move folder
In Else similar
Hope this helps ![]()
Thanks and it helped ![]()
1 Like
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.



