My goal: I have, for example, 100 files. I want the script to create a folder named 1 in the same folder where those files are located, then move 10 files out of 100 there, then create folder 2, and move 10 files out of the remaining 90 there again, and so on. Until there are no files left. But the total number of files does not have to be 100. The number can be odd, so the last folder can have fewer files.
Here is my code with explanations:
Code: Select all
FileSelectFile, SourceFile, 3,, OPEN THE LIST WITH FILE NAMES, Text File (*.txt) ; Here I specify a list of files ordered in ascending order, by size. I don't yet know how to write code so that AHK itself will order the files this way and move the files from smaller to larger. Moreover, it will increase my code a lot. Therefore, I decided to create a list of files in advance through CMD - dir /s /b /OS > list.txt
if (SourceFile = "")
Return
folderName := 0
increaseDirName: ; I assume that because of this label, the script creates an infinite number of folders after successfully moving 10 files to folder 1.
++folderName
FileCreateDir, D:\%folderName%
Loop, read, %SourceFile% ; The loop reads lines from my file, one at a time, then sends to the move subroutine.
{
FileNameLine := A_LoopReadLine
Gosub, MoveFiles
If (A_Index = 11)
Break ; I stop the loop after moving 10 files.
}
Goto, increaseDirName ; After moving the 10 files, I send the script to label increase the variable by 1 and create a folder with a new name.
MoveFiles: ; Move subroutine.
FileMove, %FileNameLine%, D:\%folderName%
Return
I suppose I can do without GoTo, but I don't know how to reset the A_Index in the loop, after moving, especially if the loop is stopped and started again, then the script will look for files from the list that are already moved, in that case the loop does not need to be stopped?
If there is a way to solve my problem without creating a list.txt, moving the files directly, as long as they will be ordered by increasing size, then I am willing to consider this solution.
Thanks in advance to anyone who can help me solve this problem.