Solved

Include Folder name in newly created Files

Posted on 2013-06-05
4
238 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now