?
Solved

Include Folder name in newly created Files

Posted on 2013-06-05
4
Medium Priority
?
250 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 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

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!
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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