Solved

Include Folder name in newly created Files

Posted on 2013-06-05
4
246 Views
Last Modified: 2013-06-06
Hello,
This is in reference to this previous question:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Q_28050669.html 
Let’s say the Main folder path is C:\Main\FolD
This folders has several files that will be distributed between the newly created folders. The code does that. What is needed now – if the main folder name is “Array”, then create 3 or whatever number of folders that start with the main folder name like
FoldD_part1
FoldD _part2
FoldD _part3 etc

Right now the code creates the new folders with name as part 1 part 2, part 3 etc .
0
Comment
Question by:Rayne
  • 2
  • 2
4 Comments
 

Author Comment

by:Rayne
ID: 39224095
All experts are welcomed :)
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39224900
There seems to be a contradiction in your question regarding the exact folder names (mainly what is “Array”?), but hopefully I understood correctly; I added the name of the folder being processed on lines 12 and 20 (and in the call on line 3):
Option Explicit

Call Folderrize("C:\main\FolD", 3)

Sub Folderrize(strFolder, intParts)
	Dim objFSO, objFolder, intNumFiles, intNumFilesPerPart, intCounterFolder, intCounterFile, intCounterFileThisPart, objFile
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFolder = objFSO.GetFolder(strFolder)
	intNumFiles = objFolder.Files.Count
	intNumFilesPerPart = 1 + Int((intNumFiles - 1) / intParts)
	For intCounterFolder = 1 To intParts
		If Not objFSO.FolderExists(strFolder & "\Part" & intCounterFolder) Then objFSO.CreateFolder(strFolder & "\" & objFolder.Name & "_part" & intCounterFolder)
	Next
	intCounterFolder = 1
	intCounterFileThisPart = 0
	intCounterFile = 0
	For Each objFile In objFolder.Files
		intCounterFileThisPart = intCounterFileThisPart + 1
		intCounterFile = intCounterFile + 1
		objFile.Move strFolder & "\" & objFolder.Name & "_part" & intCounterFolder & "\"
		If intCounterFile < intNumFiles And intCounterFileThisPart >= intNumFilesPerPart Then
			intNumFilesPerPart = 1 + Int((intNumFiles - 1 - intCounterFile) / (intParts - intCounterFolder))
			intCounterFolder = intCounterFolder + 1
			intCounterFileThisPart = 0
		End If
	Next
	Set objFolder = Nothing
	Set objFSO = Nothing
End Sub

Open in new window

0
 

Author Comment

by:Rayne
ID: 39225994
Thanks Robert :)
This is PERFECTION to the Ultimate. Thank you
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39226199
You're welcome, and thanks for your kind words!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question