473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Split a big folder

Hi all,

I have a big folder its size is 3G I like to split it to multiple folders.Everyone has a suggestion please give me. Thanks
May 31 '07 #1
15 4600
Killer42
8,435 Expert 8TB
I have a big folder its size is 3G I like to split it to multiple folders.Everyone has a suggestion please give me. Thanks
Can you provide some more details about your situation?

My first reponse would be, why don't you just use Windows Explorer to create another folder, and move half your files into it?

Does this question have anything to do with Visual Basic?
Jun 1 '07 #2
Good Morning Mod,

I have no clue to do. Please show me the way.

I like to split a big folder to 10-20 small folders. I like to use VB or any kind software.

Browse a folder---->split button (command) .... It will create multiple folders on the path that is assigned and transfer files to these folders.

Have a good weekend.
Jun 1 '07 #3
My folder is big including over 40000 files and everytime it is opened and taken time on that. I like to divide it to mulitple folders and each folers has around 1000 files depends on the size of each file.

I like to set for each folder has a limit size 100M.

The first reason I don't do manually that I like to learn how to split, second I will have more big folders so I like to save time in the future.
Jun 1 '07 #4
kadghar
1,295 Expert 1GB
Good Morning Mod,

I have no clue to do. Please show me the way.

I like to split a big folder to 10-20 small folders. I like to use VB or any kind software.

Browse a folder---->split button (command) .... It will create multiple folders on the path that is assigned and transfer files to these folders.

Have a good weekend.
Well, you can always use VBA as a file manager, I have no idea what you want it for, but i had fun making it. here you go : (change NumFolders in order to make 10 or 20 or whatever u want)

Expand|Select|Wrap|Line Numbers
  1. Sub carpetas()
  2. Dim i As Integer
  3. Dim j As Integer
  4. Dim Str1 As String
  5. Dim Int1 As Integer
  6. Dim Obj1 As Object
  7. Dim NumFolders As Integer
  8.  
  9. NumFolders = 10
  10.  
  11.  
  12. With Application.FileDialog(msoFileDialogFolderPicker)
  13.     .AllowMultiSelect = False
  14.     .Show
  15.     If .SelectedItems.Count > 0 Then
  16.         Str1 = Dir(.SelectedItems.Item(1) & "\" & "*.*")
  17.         Set Obj1 = CreateObject("Scripting.FileSystemObject")
  18.         For j = 1 To NumFolders
  19.             Obj1.CreateFolder .SelectedItems.Item(1) & "\Folder" & j
  20.         Next
  21.             j = 1
  22.         While Str1 <> ""
  23.             Obj1.CopyFile .SelectedItems.Item(1) & "\" & Str1, .SelectedItems.Item(1) & "\" & "Folder" & j & "\" & Str1, False
  24.             Obj1.DeleteFile .SelectedItems.Item(1) & "\" & Str1, True
  25.             Str1 = Dir()
  26.             j = j + 1
  27.             If j = NumFolders + 1 Then
  28.                 j = 1
  29.             End If
  30.         Wend
  31.     End If
  32. End With
  33.  
  34. End Sub
Jun 1 '07 #5
My folder is big including over 40000 files and everytime it is opened and taken time on that. I like to divide it to mulitple folders and each folers has around 1000 files depends on the size of each file.

I like to set for each folder has a limit size 100M.

The first reason I don't do manually that I like to learn how to split, second I will have more big folders so I like to save time in the future.
I was thinking more of something like this, it may take a while with 40000+ files but it works just fine...

Expand|Select|Wrap|Line Numbers
  1.     Private Sub sortFolder(ByVal selFolder As String, ByVal newFolName As String)
  2.         On Error Resume Next
  3.  
  4.         'set the selected folder
  5.         Dim selPath As String = selFolder
  6.  
  7.         'set the size variable to calculate the total size of the new folder
  8.         Dim newSize As Integer = 0
  9.  
  10.         'get the directory info for the selected folder
  11.         Dim dInfo As New System.IO.DirectoryInfo(selPath)
  12.  
  13.         'iterate through the the first thousand files in the selected folder
  14.         For i As Integer = 0 To 999
  15.  
  16.             'if we reach the end of the list, exit the for loop
  17.             If i >= dInfo.GetFiles.Length Then Exit For
  18.  
  19.             'set the folder name (you can change to whatever you want)
  20.             Dim folderName As String = newFolName
  21.  
  22.             'set the new folder path
  23.             Dim curFolder As String = selPath & "\" & folderName
  24.  
  25.             'make the new folder
  26.             MkDir(curFolder)
  27.  
  28.             'if we reach the end of the list then we exit
  29.             If i >= dInfo.GetFiles.Length Then Exit For
  30.  
  31.             'set the current file
  32.             Dim curFile As String = dInfo.GetFiles.GetValue(i).ToString
  33.  
  34.             'copy the file to the new folder
  35.             FileCopy(selPath & "\" & curFile, curFolder & "\" & curFile)
  36.  
  37.             'delete the old file
  38.             Kill(selPath & "\" & curFile)
  39.  
  40.             'set the new folder directory info and size to zero
  41.             Dim newFolderInfo As New System.IO.DirectoryInfo(curFolder)
  42.             newSize = 0
  43.  
  44.             'iterate through the files in the new folder and adds the size of each
  45.             For n As Integer = 0 To newFolderInfo.GetFiles.Length - 1
  46.                 newSize += FileLen(curFolder & "\" & newFolderInfo.GetFiles.GetValue(n).ToString)
  47.             Next
  48.  
  49.             'if the new folder's size is greater than or equal to 100MB we exit the loop
  50.             If newSize >= 104857600 Then
  51.                 Exit For
  52.             End If
  53.         Next
  54.  
  55.         'display complete message
  56.         MsgBox("File sort complete" & vbCrLf & "New Folder - " & newFolName & " - " & _
  57.         FormatNumber(newSize / 1024 / 1024, 2) & " MB")
  58.     End Sub
  59.  
Put this sub in your project and it will go through the first thousand files in selFolder, create a new folder in the selected folder named newFolName. All the files will go in this folder until it reaches 1000 files or 100MB.

If you want to do it for all of the files in the folder you should use it like the following: (put in a button_click event)

Expand|Select|Wrap|Line Numbers
  1.         Dim folBrowse As New FolderBrowserDialog
  2.         folBrowse.ShowDialog()
  3.  
  4.         Dim dirInfo As New System.IO.DirectoryInfo(folBrowse.SelectedPath)
  5.         Dim index As Integer = 0
  6.  
  7.         Do Until dirInfo.GetFiles.Length = 0
  8.             sortFolder(folBrowse.SelectedPath, "newfolder" & index)
  9.             index += 1
  10.         Loop
  11.  
  12.         MsgBox("Completely done")
  13.  
This little piece will open a folder browser dialog and go through the selected folder until the file count reaches 0. You can change newfolder to anything you wish, but it will append a number to the end of the folder to make it unique. Hopefully this helps.
Jun 1 '07 #6
Killer42
8,435 Expert 8TB
Thanks for that, CoMPMStR. Just one quibble - won't you overflow newSize rather quickly?

I generally discourage the use of the Integer type for anything, unless you desperately need to save memory. The Long type is actually slightly faster to process, at least on a 32 bit processor.
Jun 3 '07 #7
Thanks for that, CoMPMStR. Just one quibble - won't you overflow newSize rather quickly?

I generally discourage the ue of the Integer type for anything, unless you desperately need to save memory. The Long type is actually slightly faster to procss, at least on a 32 bit processor.
I'm always glad to help if I can. I just hope he's using .NET and not VB6. =/ I didn't know that the variable type would determine how fast an execution is processed. I always thought it was the CPU speed that determined process speed. The newSize variable will only overflow if the total filesizes in the new folder are greater than or equal to 2GB right? Or is it 4GB in .NET? So that means the next file in the list would have to be really large, like the size of a DVD image. It will never get that big because it always resets back to zero before adding the filesizes, and also, the 100MB check. If newSize is greater than 100MB it will exit, this should prevent it from any overflow errors. If not, it can simply be changed.
Jun 3 '07 #8
Killer42
8,435 Expert 8TB
I'm always glad to help if I can. I just hope he's using .NET and not VB6. =/ I didn't know that the variable type would determine how fast an execution is processed. I always thought it was the CPU speed that determined process speed.
Certainly the processor speed is a much bigger factor. But different instructions can take different numbers of cycles to complete, of course. A program which does twice the work will always take twice as long, regardless of how long that is.

The plain fact is that on a 32 bit processor, obviously, processing a 32 bit (four-byte) chunk of data takes one instruction (however many cycles that may require). But to work with a 16-bit (two-byte) Integer (I'm talking about VB6 now) requires extra instructions to convert back and forth. (The 32-bit "long integer" is thus referred to as the "native" data type). It's not a huge difference, of course, but I've always figured that unless you have a good reason to overlook it, why not use the quicker type? Or to put it another way, when weighing up which way to go, a small boost in processing speed (32-bit Long) is generally worth more than a very slight reduction in memory useage (16-bit Integer).

The newSize variable will only overflow if the total filesizes in the new folder are greater than or equal to 2GB right? Or is it 4GB in .NET? So that means the next file in the list would have to be really large, like the size of a DVD image. It will never get that big because it always resets back to zero before adding the filesizes, and also, the 100MB check. If newSize is greater than 100MB it will exit, this should prevent it from any overflow errors. If not, it can simply be changed.
I don't know about VB.Net, suppose we'll have to check up on that. But in VB6 the Integer data type is a 16-bit integer, which will overflow at 32,768. This is why I brought up the subject, though it looks as though I may be simply out of date.
Jun 4 '07 #9
Killer42
8,435 Expert 8TB
Ok, further info from MSDN.

You're right, Integer, in VB.Net, is now a 32-bit integer. See http://msdn2.microsoft.com/en-us/lib...z3(VS.71).aspx for a table listing the differences. But in brief, VB6 "Integer" = VB.Net "Short" while VB6 "Long" = Vb.Net "Integer".
Jun 4 '07 #10
Thanks for your responses. I will try to do my stuff with all your ideas.
Jun 4 '07 #11
What is the different .net and VB? do i need to get software for .net? I'm just a beginner in programming. Thanks
Jun 5 '07 #12
Killer42
8,435 Expert 8TB
What is the different .net and VB? do i need to get software for .net? I'm just a beginner in programming. Thanks
.Net is Microsoft's new framework for doing things in Windows. I don't know how to describe it better - go to MS, or maybe Wikipedia would be better, for more info.

VB has been around for a long time, and was up to version 6 before MS introduced the .Net framework. So VB6 is the last "pre-dotNet" version. And in the opinion of certain people, still the best available. VB.Net refers to the versions created to work with the .Net framework. I can't really comment on it, since I still use VB6.

If you are planning to learn one, I would definitely recommend you go with the latest version (VB 2005, I believe). Although I love VB6, it is at least 9 years old. It will make much more sense to learn an up-to-date development environment. (Plus, VB 2005 Express edition is available as a free download, apparently.)
Jun 7 '07 #13
Thanks all of you help me to know more VB.Net

Dim selPath As String = selFolder
Dim newSize As Integer = 0
Dim i As Integer

Dim dInfo As New System.IO.DirectoryInfo(selPath)
Dim folderName As String = newFolName
Dim curFile As String
Dim curFolder As String = selPath & "\" & folderName


MkDir(curFolder)

For i = 0 To 9
If i >= dInfo.GetFiles.Length Then
Exit For

End If




curFile = dInfo.GetFiles.Clone(i).ToString
FileCopy(selPath & "\" & curFile, curFolder & "\" & curFile) Kill(selPath & "\" & curFile)


Next 'end of of i
If I have 6 files and I assign i is reached to 9. It will created 3 folders that contain 3 files, 2 files and 1 file.

When I watch a value of i =0,1,2 then these steps happen

curFile = dInfo.GetFiles.Clone(i).ToString
FileCopy(selPath & "\" & curFile, curFolder & "\" & curFile)
Kill(selPath & "\" & curFile)

Then i =3..9, curFile still get a value of i=2.

How can I fix it. Please give me a hint. Thanks.
Jun 12 '07 #14
I was out looking for information on how to do just what you guys are doing. Thanks so much for the code. This is a big help. I am going to work on creating a program to automate one of our in house processes at my company where we have to split folders into smaller chunks for processing.
Apr 17 '08 #15
Killer42
8,435 Expert 8TB
I was out looking for information on how to do just what you guys are doing. Thanks so much for the code. This is a big help. I am going to work on creating a program to automate one of our in house processes at my company where we have to split folders into smaller chunks for processing.
Glad you found this helpful. :)

That's what is so great about an open forum like this. Apparently at some sites you can read the questions, but have to pay to read the answers - ugh!
Apr 19 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave Elliott | last post by:
I have a db that is split and shared on the network. I gave the user a custom menu to use. We both use the same tables of course. On my PC I can create new records using their menu on my PC, on...
12
by: Corey Burnett | last post by:
I have a client that has a split database (front-end/back-end). They are also using Access security - MDW file. The front end MDE file, the back end MDB file, and the MDW file are all located on...
1
by: Tardus Merula | last post by:
We have just put a new samba server on the lab premises and upgradede all workstations to 100 MB/s, in order to avoid using 10-mile radio link, hoping that this would enable us to operae our...
3
by: Andi Twine | last post by:
Hi all, I really hope someone here can help ! I have designed and built an ASP.NET web service with Visual Studio .NET. The web service outputs some dummy XML data when its called with some...
1
by: Krish | last post by:
I have requirement, that i get one big chunk of text file. This text file will have has information, that on finding "****End of Information****", i have to split them individual text file with our...
0
by: erikjalevik | last post by:
I have now spent the best part of a day trying to find out how to distribute our unmanaged C++ app built with a newly purchased copy of VS2005. As per all the other posts, it runs fine on the dev...
3
by: najimou | last post by:
Hi everyone I will be having a split database, running on 2 computers via mapped drive. computer "A" will have one front end and the back end located in c: \mydatabse 2 tables have links to...
6
by: Brian Roisentul | last post by:
Hi everyone, I've been investigating for a while about this, but with no luck yet. Does anybody know a way to do it? Many thanks, Brian
21
by: =?ISO-8859-1?Q?Fad=A5?= | last post by:
Hello guys, I want to do kinda of an A/B split testing on a website I run. I just created a new version but I need to keep both version running and see which one will perform better. First, I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.