Move files to new folder with oldest file's name?

Hi there
The purpose of this post is to check how this problem/requirement is best solved.
I think it could be scripted but my scripting skills are limited really to analysing and editing existing scripts...
Would it be feasible to script a solution for this?
Many thanks as always for any responses....
This link shows a video of what I do by hand very very often and it would be great if I could somehow reduce this to clicking a button.....

Draft Spec:
C1 Consider a list of files with a date-time prefix and an optional text suffix with any extension.
This would be of the following filename format:

YYYY-MM-DD HHhMMmSS.ext
or
YYYY-MM-DD HHhMMmSS SUFFIX TEXT.ext

For example this list of files below:

2019-01-18 12h03m26
2019-01-18 11h27m15
2019-01-18 11h25m45
2019-01-18 11h14m44 North Rd duplex print
2019-01-18 11h14m12
2019-01-18 11h00m53
2019-01-18 10h50m03 SD-WAN SandPit Booking3
2019-01-18 01h13m38
2019-01-17 21h46m23
2019-01-17 21h40m53
2019-01-17 21h37m11
2019-01-17 21h35m44
2019-01-17 20h00m00

N.B. the list above shows the filename stems only. The extensions are missing.

C2 Call this the SELECTED FILES.

C3 Consider that the folder is sorted using Filename (Folder Options > Columns tab > Filename field checked).

C4 Consider that the Reverse sort order option is enabled (Folder Options > Display tab > Reverse sort order field checked)

C5 Considerations C3 and C4 have the effect of sorting the filenames in chronological order most recent at the top. See file list above for example.

C6 Consider the file list to be selected. i.e. All files in the list are highlighted.

The above considerations describe the conditions under which the desired script should be executed.
Below is described the actions which the script should execute:

A1 A popup should appear prompting for text. Call this the FOLDER SUFFIX TEXT.

A2 The file at the bottom of the list above is the file with the oldest date/time stamp.
In the example above this file name stem is:
2019-01-17 20h00m00
Call this the OLDEST FILENAME
A folder should be created in the current directory with the following name:
<OLDEST FILENAME> <FOLDER SUFFIX TEXT>
There is a single space between the 2 parameters above.
If the FOLDER SUFFIX TEXT is blank then the folder name should be <OLDEST FILENAME>.

A3 All the SELECTED FILES should be moved to the newly created folder

A4 All SELECTED FILES should now be in a folder in the current directory named
2019-01-17 20h00m00 Blah
Where blah is the FOLDER SUFFIX TEXT entered in A1 above (if any)

A5 Script should end.

Hi Leo
I was editing my post but had a "Edit confict" with your name popping up.
So I cancelled assuming you were fixing up my formatting mistakes.
So I have backed off for the moment...

I'm done now. Was just fixing the < ... > parts which were invisible initially.

1 Like

Here is a little solution with two buttons, open for further automation.

Step 1: Sort and select

Set SORTBY=modified
Select LAST

Step 2: Move

Copy MOVE HERE FILE=*.* CREATEFOLDER="{dlgstring|Enter new folder:|{file|noext}}"

Is this going in the direction you had in mind?

@Ixp thanks so it may be this does not have to be scripted necessarily..
I will test examine and test that really appreciate the feedback thanks..

Thanks... have played around with this.
The sequence above (SET1) moves all files in the folder into a subfolder which is created with the very useful dlgstring popup code
The dlgstring populates with the first filename which may not be a problem I could live with that I think to start with anyway. So I just type in the suffix I want and hit enter and the folder is then created.

So now I need to fiddle with this method so that only SELECTED files are copied to the newly created folder.
SELECTED files are the default if no other FILE spec if given so I just drop the
FILE=*.*
and tried this below (Set2):
Copy MOVE HERE CREATEFOLDER="{dlgstring|Enter new folder:|{file|noext}}"
This indeed only copies the selected files but for some reason Set2 above creates a folder for each and every selected file. It seems to execute the same operation n times where n is the number of files selected.
Your command sequence (Set1)above executed one operation on n selected files.

Next I looked at the Command Modifier Reference to see if there was something available to force a single operation on all selected files instead of single operation on each file.
I tried this below (Set3):
@runonce:Copy MOVE HERE CREATEFOLDER="{dlgstring|Enter new folder:|{file|noext}}"
This acted on the first/top file in the selection then did not do all the rest. Only 1 file moved to the new folder all the other files untouched.

Set4 below created a folder successfully nothing else. It proved I got the syntax right for creating the folder though. I thought maybe the selection was lost in creating the file so there was nothing selected when the COPY came to execute?
It is straight out of the Command Modifier Reference:

@set dir={dlgstring|Enter new folder name to copy files to}
CreateFolder ".\{$dir}"
Copy TO ".\{$dir}

Alas Set5 below producres an error creating the folder. Tried for simple folder name e.g. no spaces but no avail:

@set dir="{dlgstring|Enter new folder:|{file|noext}}"
Copy MOVE HERE CREATEFOLDER=".\{$dir}"

This is the error I am getting:
image

This is all I can think of to try right now.
@Ixp thanks again if nothing else I am learning a bit...

This should work:

@runonce:@set dir={dlgstring|Enter new folder name to copy files to}
Copy MOVE HERE CREATEFOLDER="{$dir}"

To get the folder name right, you could in a first step move all the files to a temp folder and then in step 2 rename that folder to the oldest file's name.

Bingo! Call the above Set6.
Set6 prompts for a foldername then moves all the selected files into that folder.

So I reintroduced what must be the switch to populate the dlgstring popup dialog with the what turns out to be the top filename in the selection. I give you Set7:

@runonce:@set dir={dlgstring|Enter new folder:|{file|noext}}
Copy MOVE HERE CREATEFOLDER="{$dir}"

This copied all the selected files into a newly created folder.
The popup text prompt is populated with the filename of the top/first file in the section.
I originally wanted the bottom but the top file will do very happy with this.
The sequence is below:
image

image

Ixp you have made my life easier and taught me a few things thankyou sir!!!
:sunglasses::sunglasses::sunglasses::sunglasses::sunglasses: