HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tweacle
Posts: 67
Joined: 11 Apr 2018 05:38

HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

#1 Post by tweacle » 16 Nov 2018 04:39

Hi

I have a folder of which contain files of all different sizes.

What im trying to do is have a script that runs in order starting from the top of the list moving files into new sub folders but only upto 4gb of data in each folder.

Lets say I got 6 folders

1- 2gb
2- 750mb
3- 4 gb
4- 3 gb
5- 1gb
6- 3gb

What I would need to do is move files 1 &2 into a new folder as file 3 would take it over the limit.
Then file 3 into new on on its own as is the limit
Then files 4 & 5 together as the limt and finally file 6 and next file if less that 1gb.

Folder where original download is in is X:\DOWNLOADS

and new location I need them is X:\DOWNLOADS\SPLIT and then all the subfolders as numbers.

The files will not be all the same size .

I know how to use robocopy but thats about it.

Any Ideas.

Thanks.

tweacle
Posts: 67
Joined: 11 Apr 2018 05:38

Re: HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

#2 Post by tweacle » 16 Nov 2018 12:16

Ive had a little go and I know its not a lot to start and have come up with this so far

xcopy /s X:\DOWNLOADS X:\DOWNLOADS\SPLIT
del /S X:\DOWNLOADS*

What I need it to do now is go through X:\DOWNLOADS\SPLIT in file order starting at the top and move files into sub folders upto 4gb in size as shown above.

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

Re: HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

#3 Post by ShadowThief » 16 Nov 2018 13:28

del /S recursively deletes all files in that folder and in all subfolders. Using it would be a terrible waste of an xcopy.

Also, because you're working with file sizes in the gigabytes, you need to do math with numbers larger than the 32-bit maximum, which batch can't natively do.

Aacini
Expert
Posts: 1564
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

#4 Post by Aacini » 16 Nov 2018 15:44

Here it is a possible solution. I removed the three last digits of the file size in order to perform operations with this number via SET /A command; I think this mod should not impact the result in any way. For my testings I create several text files and placed their sizes inside the files, so you must remove the line that process the file this way and enable (remove the comment from) the next line.

Code: Select all

@echo off
setlocal EnableDelayedExpansion

REM cd /D X:\DOWNLOADS
REM md SPLIT

set /A "curSize=5000000, folder=100"

for %%f in (*.txt) do (
   for /F "usebackq delims=" %%s in ("%%f") do set "size=%%s"
   rem Remove previous line and use: set "size=%%~Zf"
   echo Moving file "%%f" of size !size! Bytes
   set "size=!size:~0,-3!"
   set /A "newSize=curSize+size"
   echo New size in folder including this file would be !newSize!
   if !newSize! gtr 4294967 (
      echo/
      echo Creating a new folder
      set /A "folder+=1, curSize=0"
      ECHO md SPLIT\!folder:~1!
   )
   ECHO move "%%f" SPLIT\!folder:~1!
   set /A "curSize+=size"
   echo Current size is !curSize! KBytes
)
This is the output of this test:

Code: Select all

Moving file "1- 2 GB.txt" of size 2147483648 Bytes
New size in folder including this file would be 7147483

Creating a new folder
md SPLIT\01
move "1- 2 GB.txt" SPLIT\01
Current size is 2147483 KBytes
Moving file "2- 750 MB.txt" of size 786432000 Bytes
New size in folder including this file would be 2933915
move "2- 750 MB.txt" SPLIT\01
Current size is 2933915 KBytes
Moving file "3- 4GB.txt" of size 4294967296 Bytes
New size in folder including this file would be 7228882

Creating a new folder
md SPLIT\02
move "3- 4GB.txt" SPLIT\02
Current size is 4294967 KBytes
Moving file "4- 3 GB.txt" of size 3221225472 Bytes
New size in folder including this file would be 7516192

Creating a new folder
md SPLIT\03
move "4- 3 GB.txt" SPLIT\03
Current size is 3221225 KBytes
Moving file "5- 1 GB.txt" of size 1073741824 Bytes
New size in folder including this file would be 4294966
move "5- 1 GB.txt" SPLIT\03
Current size is 4294966 KBytes
Moving file "6- 3 GB.txt" of size 3221225472 Bytes
New size in folder including this file would be 7516191

Creating a new folder
md SPLIT\04
move "6- 3 GB.txt" SPLIT\04
Current size is 3221225 KBytes
IMPORTANT: I assume you know Batch file programming. If you have doubts about simple points of specific commands, please review they in anyone of the sites that exists on Batch file programming. If you still have doubts about the mechanism of this program, then post a question here. However, be sure to first read the first post in this site.

Antonio

tweacle
Posts: 67
Joined: 11 Apr 2018 05:38

Re: HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

#5 Post by tweacle » 17 Nov 2018 05:41

Thanks Aacani

Unfortunally in not that far forward in scripts and im confused over what you said below.

Code: Select all

For my testings I create several text files and placed their sizes inside the files, so you must remove the line that process the file this way and enable (remove the comment from) the next line.
Sorry

Aacini
Expert
Posts: 1564
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: HOW DO I MOVE DATA INTO SUB FOLDERS UPTO 4GB IN SIZE

#6 Post by Aacini » 17 Nov 2018 19:09

@tweacle,

Ok. This phrase means that you must locate the line that process the data inside the file and remove it. To know which line process the data inside the file, you may investigate what is the purpose of each line in this program (hint: the line you need to remove is the line before the one that said: "Remove previous line").

After that, you need to "enable the next line", that is, to "remove the comment from it". A "comment" is a phrase placed after the command used to insert comments (like "Remove previous line and use:") and then use the part that is after "and use:".

If you are not capable of do this, then you couldn't use this program...
Sorry

Post Reply