Save files from one folder to another folder one after the other according to their name

Hello, everybody,

the files in my source folder should be saved one after the other in another folder for evaluation purposes according to their file names. The name of the files is made up of the four-digit number of the company, the year and the month in question (e.g. 1000_2016_1.zip).The individual folders contain data for a certain Company for one specific month of one specific year. A total of 20 companies and 3 years (2016 - 2018) are considered.

First the data of the month January (=1) of year 2016 of company 1000 should be stored in the new Folder (file name: 1000_2016_01.zip), then the data of the following months of the year (up to 1000_2016_12.zip) should be stored.

Then the data of year 2017 of the same company (1000_2017_01.zip - 1000_2017_12.zip).
The same procedure should be applied for the 20 other companies (1001_2016_1.zip etc.).

How can I solve the Problem? Do I Need to store the filenames in a list before?

Kind regards
Lena

I Need to find a solution as the Folders are supposed to be unzipped and evaluated individually in a specific order, therefore I Need to save one by one to the new Folder, evaluate the file, delete it and save the next file to the new Folder for Evaluation.

Let me understand:

You have zip files with this structure in name
XXXX_YEAR_MM where XXXX is a Number, YEAR is year (4 digits) and MM is month (2 digits)
You need to unzip them (sorted) and put in a specific path for processing, after that, clean and unzip next and so on… Right?

Hey, exactly. I already created a Process to unzip, evaluate and delete a file once it is already saved to the new Folder. I just don’t really know how to create a Loop to save the zip-files there initially.

One of my colleagues said I will Need 3 Loops (one for Company, one for year and one for month)

Do you need to creat zip file first?

  1. zipfile = System.IO.Compression.ZipFile.Open(path_to_zip ,ZipArchiveMode.Create)
  2. For each File you want to zip,
    2.1 zipentry = zipfile.CreateEntryFromFile(path/to/your/file.any, “file.any”)
  3. zipfile.Dispose()

Is this what you need to do?

Hey,

all files are stored in one specific order as zip files. The Robot is supposed to unzip them one by one and evaluate the data contained in the file.

Therefore, I want to save one zip-file to a new Folder, unzip it, evaluate it and empty the Folder to unzip the next file.

You could create a list of zip files with Directory.GetFiles() method, after that, apply kind of “sort” using LINQ capabilities and use a loop to iterate list, unzip and process.

Hmm, my Issue is hard to explain I guess :). To start all over, is it possible to split the file Name into 3 integer variables (Company, year, month)?