Page 1 of 2
Combine files to specific size folders
Posted: 17 Apr 2022 11:59
by noembryo
I don't know if this is better on the "Wishes" section but..
A tedious thing I have to do some times is to split the files of a directory to many folders that have a certain size.
This is needed if for example they must be send to a container, physical (DVD, USB stick) or virtual (distribute images in zips..).
What it needs, is an input dialog to enter the size (could be nice to select Kb, Mb, Gb..) and perhaps an option to add the files in a serial order or by using the best order that gets as close to the target as possible.
Maybe it could be a feature of the app?
Maybe it already exists and I totally missed it?
Anyway, thanks for your time..
Edit: Attached is a zip with an XYplorer script and a Python script.
These two must be in the scripts folder of XYplorer to work.
What it does (for now) is that it takes an input from the user, like:
500Mb or 1.2Gb or 500000 or 640000.4kb
and re-distributes the files of the current directory to as many folders (of the size that we specified) is needed.
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 14:46
by highend
A script wouldn't be the best way to solve this. At least not, if there can be many files or if a better strategy than adding files sequentially should be used. The correct optimization would just take way too long (no internal arrays, list or maps are available)...
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 17:24
by noembryo
Then, maybe a simple way to open a dialog with a spinbox (to get the number), a checkbox (to get the sequential option) and a way to lunch a python script that does this?

Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 19:59
by highend
There is no XY-inbuilt spinbox, you would use either a html form or a normal input window.
Ofc you can call it from XY if you have the necessary python script...
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 20:07
by noembryo
highend wrote: ↑17 Apr 2022 19:59
There is no XY-inbuilt spinbox, you would use either a html form or a normal input window.
I'm reading some scripts made by others to see how they do it.
So if I find enough time for this..
Ofc you can call it from XY if you have the necessary python script...
Is this easier?
I need to pass some arguments to the python script I'll make.
How can you do it?
Total novice in XYplorer scripting here, but I'm OK with Python..
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 20:27
by highend
Is this easier?
No, it's faster
How can you do it?
Do what, call a python script? Depends on if the python script returns anything or does the whole work (finding the group of files, creating the dirs and move the files) or not. run / runret()...
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 20:54
by noembryo
highend wrote: ↑17 Apr 2022 20:27
Do what, call a python script? Depends on if the python script returns anything or does the whole work (finding the group of files, creating the dirs and move the files) or not. run / runret()...
No, I meant how you send arguments to the script.
Yes, the script will do all the work.
What I try to find is a way to send the "Dir size", a switch option (sequential/optimum) and the selected files (or at least the current dir) to the script..
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 21:13
by highend
Code: Select all
run lax("python" "{some path}\{your python script}.py" "<curpath>" "650");
and python stores these arguments in
sys.argv[1] and onwards...
Re: [REQ] Combine files to specific size folders
Posted: 17 Apr 2022 23:37
by noembryo
highend wrote: ↑17 Apr 2022 21:13
Code: Select all
run lax("python" "{some path}\{your python script}.py" "<curpath>" "650");
Thank you, its working..
Now lets try to do the thing..

I'll post my results..
Re: [REQ] Combine files to specific size folders
Posted: 18 Apr 2022 15:57
by noembryo
OK, I uploaded a script at the first post (with the accompanying python script).
It seems to be working, but every input (specially for speed optimizations) is welcome.
OTOH, does anyone know of a way to suppress the command line window that opens when the .py is executed.
The command I use is run lax("python" "<xyscripts>\Distribute files to folders.py" "<curpath>" $text); (as sugested by @highend).
Re: [REQ] Combine files to specific size folders
Posted: 18 Apr 2022 16:32
by highend
Read the entry for run in the help file?
Re: [REQ] Combine files to specific size folders
Posted: 18 Apr 2022 16:42
by noembryo
highend wrote: ↑18 Apr 2022 16:32
Read the entry for
run in the help file?
Hmm, no, I didn't.
And this brings me to another question that I don't thing it has to do with the XYplorer's programming, but here it is:
How can i make the Help window use dark colors as background.
I use win7, and it does not support themeing.
Since I have an eye "condition", I can not read really bright pages, and the help has the most white of them all!
Edit: Of course, you are right, and I updated the script with the change..

Re: [REQ] Combine files to specific size folders
Posted: 18 Apr 2022 17:43
by highend
Are you sure, that this works correctly?
From a command prompt:
Code: Select all
"D:\Tools\@Scriptlanguages\Python3_x64\python.exe" "R:\Downloads\Distribute files to folders v0.1.0\Distribute files to folders.py" "R:\test\@files" "400kb"
While
R:\test\@files
contains 21 files with an overall size of 1,35 MB
The python script runs endlessly...
Re: [REQ] Combine files to specific size folders
Posted: 18 Apr 2022 17:54
by noembryo
highend wrote: ↑18 Apr 2022 17:43
Are you sure, that this works correctly?
From a command prompt:
Code: Select all
"D:\Tools\@Scriptlanguages\Python3_x64\python.exe" "R:\Downloads\Distribute files to folders v0.1.0\Distribute files to folders.py" "R:\test\@files" "400kb"
While
R:\test\@files
contains 21 files with an overall size of 1,35 MB
The python script runs endlessly...
Works here.
I tested it with Python 2.7 and 3.7
Can you try to copy both files in XYplorer's scripts folder and use the
.xys script?
Re: [REQ] Combine files to specific size folders
Posted: 18 Apr 2022 17:56
by noembryo
... also check if there is an _err_log.txt in the directory that the script executes..