Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Include Folder name in newly created Files

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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