Skip to content
Advertisement

move files to subdirectories that are named on part of the filenames

I have a few data files in a directory, and I want to move them to the subdirectories based on their filenames. Let’s say we created the first directory named “20220322_170444,” and it should contain the first four files only because in the next file the “el” is less than the previous one, so the second folder, let’s say is “20220322_170533”, then it should contain next eight files until the el becomes less again than the previous name.

example data

JavaScript
JavaScript

What I tried is

JavaScript

I now have a list named sweeps, and it contains the desired files; how can I now move these files to the directories,m but the directories should be named as I stated above based on the date. I have also the date string in variable res.strftime(“%Y%m%d_%H%M%S”) can be used to create directories.

Advertisement

Answer

Some string splitting can do this for you.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement