Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
Smart Folder Creation
Logged in as: Guest
arrSession:exec spGetSession 2,16,29290
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Smart Folder Creation
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
Smart Folder Creation -
12/23/2005 4:43:13 AM
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status:
offline
This Sub will create a folder and the entire path to the folder if need be.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' '' Sub SmartCreateFolder(strFolder) '' Author: ebgreen '' Purpose: Creates a folder building the entire path if needed. '' Takes: strFolder - The complete path of the folder to create '' Returns: Nothing '' Revision History: '' 12/23/05 RMD Created '' '' To Do: '' Nothing at present '' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub SmartCreateFolder(strFolder) Dim oFSO:Set oFSO = CreateObject("Scripting.FileSystemObject") If oFSO.FolderExists(strFolder) Then Exit Sub Else SmartCreateFolder(oFSO.GetParentFolderName(strFolder)) End If oFSO.CreateFolder(strFolder) Set oFSO = Nothing End Sub
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:
http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm
Post #: 1
RE: Smart Folder Creation -
3/1/2006 8:26:35 AM
DiGiTAL.SkReAM
Posts: 1171
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status:
offline
AAARRRGGGHHH!!!!!
Why didn't i take a look thru here earlier?!? It would have saved me from havign to create this monstrosity to do the same thing!
*quietly wanders off towards the gunrack*
Function fCreateFolder(sFolderPathToCreate) ' This function checks for the existence of a folder. If it does not exist, ' it will create the folder and any parent folders that do not exist, as well. ' It can handle either UNC paths or drive letter paths. ' The function will return an error code of 0 if no errors were encountered, ' and a 1 if any errors were encountered. Dim iStartCharacterPosition, sFolderPathPrefix, sFolderPathSuffix, aFolders, iElement, sFolderName, iError, iResult If Trim(sFolderPathToCreate) = "" Or IsNull(sFolderPathToCreate) or len(sFolderPathToCreate) < 4 Then iResult = 1 Else If Not oFSO.FolderExists(sFolderPathToCreate) Then Select Case Left(Trim(sFolderPathToCreate), 2) Case "\\" iStartCharacterPosition = InStr(3, sFolderPathToCreate, "\") sFolderPathPrefix = Left(sFolderPathToCreate, iStartCharacterPosition) Case Else iStartCharacterPosition = 3 sFolderPathPrefix = Left(sFolderPathToCreate, 3) End Select If Len(sFolderPathToCreate) > Len(sFolderPathPrefix) Then sFolderPathSuffix = Right(sFolderPathToCreate, Len(sFolderPathToCreate) - iStartCharacterPosition) iResult = 0 Else iResult = 1 End If Select Case iResult Case 0 aFolders = Split(sFolderPathSuffix, "\") For iElement = 0 to UBound(aFolders) sFolderName = sFolderName & aFolders(iElement) & "\" If Not oFSO.FolderExists(sFolderPathPrefix & sFolderName) And iElement > 0 Then On Error Resume Next oFSO.CreateFolder(sFolderPathPrefix & sFolderName) iError = Err.Number On Error GoTo 0 Select Case iError Case 0 iResult = 0 Case Else iResult = 1 End Select End If Next Case Else iResult = 1 End Select Else iResult = 0 End If End If fCreateFolder = iResult End Function
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
(in reply to
ebgreen
)
Post #: 2
RE: Smart Folder Creation -
3/1/2006 9:22:22 AM
ebgreen
Posts: 4613
Score: 31
Joined: 7/12/2005
Status:
offline
Recursion is your friend.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:
http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm
(in reply to
DiGiTAL.SkReAM
)
Post #: 3
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Smart Folder Creation
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI