Split Folder in multiple folders for size !!!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Split Folder in multiple folders for size !!!

#16 Post by foxidrive » 07 Dec 2014 07:50

mingolito wrote:I do not think it needs further information to give an answer


Many of the regulars could give you an answer, that is true.
It may not work in your situation for a number of reasons, and as so many people before you have done, you'd come back and say "It doesn't work!"

Then there would be another 20 posts trying to find out about your task - which you have studiously avoided describing so far.
After the details about the task are revealed then the script would have to be rewritten.

mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#17 Post by mingolito » 07 Dec 2014 08:08

ShadowThief wrote:

Code: Select all

set /p "outputfolder="

asks the user for the path where the split folders should be saved. If you want to have it set in the code, you can specify it like

Code: Select all

set "outputfolder=C:\Test\Output"

Does not work, How do I set in the code, the split folders are created in the same folder, not in a folder of your choice. :?

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Split Folder in multiple folders for size !!!

#18 Post by ShadowThief » 07 Dec 2014 17:25

The source directory (which you also want to use for the destination directory) is set by

Code: Select all

echo " Please Enter The Path Of The Root Folder To Be Split " :
set /p "folder="


and then used in

Code: Select all

for /F "tokens=*" %%G in ('dir "%folder%" /A: D /B') do (

mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#19 Post by mingolito » 08 Dec 2014 03:50

ok i solved, it was a simple thing, strange that no one has been able to give a solution:

Code: Select all

SOLVED


:wink: :wink:
Last edited by mingolito on 13 Dec 2014 16:49, edited 1 time in total.

mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#20 Post by mingolito » 08 Dec 2014 05:41

Now the question is another, wanting to use the copy command instead of move, in this way:

Code: Select all

SOLVED

So as to leave intact the files in the root folder and move only the split files in the folder of your choice of destination.
But when I execute the command does not find the folders and files in the folder split, but only the files ???
I hope someone more experienced than me can give me a hand by analyzing the script:

SOLVED
Last edited by mingolito on 13 Dec 2014 16:45, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Split Folder in multiple folders for size !!!

#21 Post by foxidrive » 08 Dec 2014 05:56


mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#22 Post by mingolito » 08 Dec 2014 06:27

foxidrive wrote:See here: viewtopic.php?f=3&t=6108


:shock: :shock: :shock:

I have not yet figured out what you are ???
One that spits it judgments, a poet retired, I have a batch programmer, which should solve the problems of others on the script posted.
in 20 post, whether you controlled my script, I have posted on the front page, instead of responding with poetic paraphrase, you gave the answer, which I found to be just ...

:wink: :wink: :wink:

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: Split Folder in multiple folders for size !!!

#23 Post by Squashman » 08 Dec 2014 07:32

mingolito wrote:ok i solved, it was a simple thing, strange that no one has been able to give a solution:
:wink: :wink:

The problem is everyone is having a hard time understanding what you are trying to do. But if you subscribe to occam's razor, then yes the answer probably was simple.

mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#24 Post by mingolito » 08 Dec 2014 08:03

The problem is everyone is having a hard time understanding what you are trying to do. But if you subscribe to occam's razor, then yes the answer probably was simple.


I understood the meaning of "occam's razor," I have to apologize, but when I write a script like this:

Code: Select all

SOLVED


or else when I asked:
wanting to modify the whole script, in the choice in number of folders to be divided, or, in the choice in size for each folder split, instead of using the chosen number of files per folder, as in posted script, you can do so ????

Although written with an Englishman wrong, it is so difficult understand what I want to ?????????
Last edited by mingolito on 13 Dec 2014 16:47, edited 2 times in total.

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Split Folder in multiple folders for size !!!

#25 Post by ShadowThief » 08 Dec 2014 13:23

Yes, actually, it is. I don't know what you think you wrote, but it is not a coherent sentence in English.

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Split Folder in multiple folders for size !!!

#26 Post by ShadowThief » 08 Dec 2014 13:39

For reference, what I think you were asking is:

I have a folder that contains subfolders and other files. I have written a script that splits the contents of my source folder into groups of x files, where x is a number of files specified by the user. I want to adjust the script so that it splits the contents into groups of x MB, where x is a size specified by the user.


And then you said
Which works great but divides the folder more 'folder with the choice of max elements...

at which point you confused me, because I don't have a clue what this means.

And then you went back and forth about whether the newly-created folders needed to be put in the source folder or not.
mingolito wrote:How do I set the output folder containing folders split?

Code: Select all

echo " Enter The Output Folder Split " :
set /p "outputfolder="?????

mingolito wrote:How do I set in the code, the split folders are created in the same folder, not in a folder of your choice.



And so in summary, yes, it was very hard to understand what you wanted.

mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#27 Post by mingolito » 08 Dec 2014 14:59

Just wondered one thing, at the beginning, if there was a chance to split a folder, in multiple folders, leaving intact the order of the files and sub folders, with the choice to set the number of destination folders, and not the number of files within each folder, starting as an example the script I posted on the front page.
But in 30 posts I had no answer it solution, surely because of my wrong English, is not the experience of decades, that this forum has in batch programming ...... :roll: :wink: :wink:
Easier than this, she could only intervene our dear Albert E. :mrgreen:

Thank you the time that have given me even though I have not found the solution I needed.. :|

miskox
Posts: 554
Joined: 28 Jun 2010 03:46

Re: Split Folder in multiple folders for size !!!

#28 Post by miskox » 09 Dec 2014 07:09

This is what you need (if I understand what you need):

http://matrixhasu.altervista.org/index. ... d_cd_optim

The program above has three different options on which files are moved to target folders: brute-force, pair swap, single swap (everything is explained at the web site).

There is a source and maybe somebody who 'speaks' JAVA can write a batch solution - not for the brute force because it would take too much time, but for some of the other two options (I would be interested for this solution, too).

Saso

mingolito
Posts: 28
Joined: 04 Dec 2014 11:34

Re: Split Folder in multiple folders for size !!!

#29 Post by mingolito » 09 Dec 2014 12:04

miskox wrote:This is what you need (if I understand what you need):

http://matrixhasu.altervista.org/index. ... d_cd_optim

The program above has three different options on which files are moved to target folders: brute-force, pair swap, single swap (everything is explained at the web site).

There is a source and maybe somebody who 'speaks' JAVA can write a batch solution - not for the brute force because it would take too much time, but for some of the other two options (I would be interested for this solution, too).

Saso

YES, the concept is to, since it is impossible to do this in batches, I guess, I'll have to choose in other methods.

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Split Folder in multiple folders for size !!!

#30 Post by Ben Mar » 05 May 2015 19:53

Try this to see if it's what you need.
This is very basic and it's not doing the real optimization at all.

Code: Select all

@echo off
if "%~1"=="" goto Help
if "%~2"=="" goto Help
if "%~3"=="" goto Help
setlocal enabledelayedexpansion
set "src=%~1"
set "dst=%~2"
set /a "size=%~3*1024*1024"
set new_folder=1
if not exist %dst%\%new_folder% md %dst%\%new_folder%
for /r %src% %%a in (*) do (
   set /a "sum+=%%~za"
   if !sum! GTR !size! (
      set sum=0
      set /a new_folder+=1
      if not exist %dst%\!new_folder! md %dst%\!new_folder!
   )
   echo move %%a %dst%\!new_folder!
)
goto eof

:Help:
echo.
echo Syntax: %0 [Source Dir] [Destination Dir] [Max Size in Mb]
echo.

:eof

Post Reply