Solved

Include Folder name in newly created Files

Posted on 2013-06-05
4
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

726 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