I have several files that have the name of the date in Julian day. Example:
- 2014353_180000
- 2014353_190000
- 2014353_200000
- 2014354_180000
- 2014354_190000
- 2015355_190000
- 2015355_200000
- ...etc.
What I want is for those files to be transferred to their respective folder, as shown below.
.
├ 2014353/
| ├─ 2014353_180000
| ├─ 2014353_190000
| └─ 2014353_200000
├ 2015354/
| ├─ 2015354_190000
| └─ 2015354_200000
etc ...
How could I do it?
I am going to assume that the files you want to move are those that start with 7 characters, all of them being figures. Of which the first four are the year and can be any. And the next 3 are the day and must be a day from 1 to 366.
I assume you want to create folders with 7 character names for those days for which there are files and move the files for those days into their directories.
As you can see first I create a list with all the files in the
dirBase
.Which I go through in a loop and for each one
esFecha
it determines if the file name fits the criteria I have defined and if so itmoverFichero
creates the directory if necessary and moves the file.Not all the work is done. You have to modify
esFecha
to take leap years into account. Or to fit your criteria if it is different. But this should point you in the right direction.