Combine files to specific size folders

Discuss and share scripts and script files...
noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Combine files to specific size folders

Post 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? :oops:

Anyway, thanks for your time.. :tup:

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.
Attachments
Distribute files to folders v0.2.0.zip
Suppress the cmd window when executing the python script
(1.58 KiB) Downloaded 65 times
Distribute files to folders v0.1.0.zip
Initial release
(1.61 KiB) Downloaded 56 times
Last edited by noembryo on 19 Apr 2022 18:14, edited 6 times in total.
Check my free programs here..

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [REQ] Combine files to specific size folders

Post 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)...
One of my scripts helped you out? Please donate via Paypal

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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? :?:
Check my free programs here..

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [REQ] Combine files to specific size folders

Post 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...
One of my scripts helped you out? Please donate via Paypal

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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..
Check my free programs here..

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [REQ] Combine files to specific size folders

Post 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()...
One of my scripts helped you out? Please donate via Paypal

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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..
Check my free programs here..

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [REQ] Combine files to specific size folders

Post 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...
One of my scripts helped you out? Please donate via Paypal

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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.. :D
I'll post my results..
Check my free programs here..

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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).
Last edited by noembryo on 18 Apr 2022 16:34, edited 1 time in total.
Check my free programs here..

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [REQ] Combine files to specific size folders

Post by highend »

Read the entry for run in the help file?
One of my scripts helped you out? Please donate via Paypal

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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! :ugeek:

Edit: Of course, you are right, and I updated the script with the change.. :tup:
Check my free programs here..

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: [REQ] Combine files to specific size folders

Post 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...
One of my scripts helped you out? Please donate via Paypal

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post 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?
Check my free programs here..

noembryo
Posts: 100
Joined: 13 Apr 2022 21:40

Re: [REQ] Combine files to specific size folders

Post by noembryo »

... also check if there is an _err_log.txt in the directory that the script executes..
Check my free programs here..

Post Reply