PDA

View Full Version : Create folder script


vpt.se
02-12-2008, 06:14 AM
Two subroutines, one 'bigger' with errorhandling and one 'smaller' and faster with no errorhandling, but should do the trick.

SCRIPT.BAS:
'
' The variable passed to this sub should contain
' the full path, i.e if you need to create "Testfolder"
' in the "C:\Programs" folder, the variable would be "C:\Programs\Testfolder"
' The subroutine first checks if the folder exist, if it does, a messagebox
' pops up telling you this, if it doesn't exist, it will (try) to create it.
'
Sub PCDCreateFolder(MyFolder As String)

Dim MyFileSysObj, f

Set MyFileSysObj = CreateObject("Scripting.FileSystemObject")

If Not MyFileSysObj.FolderExists(MyFolder) Then
Set f = MyFileSysObj.CreateFolder(MyFolder)
Else
MsgBox MyFolder & " already exists!", vbExclamation, "PCDCreateFolder"
End If

End Sub



'
' The variable passed to this sub should contain
' the full path, i.e if you need to create "Testfolder"
' in the "C:\Programs" folder, the variable would be "C:\Programs\Testfolder"
' A simpler version of the PCDCreateFolder. No messagebox, nothing.
' If the folder exists, then it skips the errormessage stating that the
' folder creation was unsuccessful and moves on. If it doesn't exist, it creates it.
'
Sub CreateDir(MyFolder As String)

On Error Resume Next

MkDir MyFolder

End Sub
'
'

Call the subroutine from PC-DMIS:

ASSIGN/FOLDERNAME = "C:\Path\to\folder"
CS1 =SCRIPT/FILENAME= C:\SCRIPT.BAS
FUNCTION/PCDCreateFolder,SHOW=YES,ARG1=FOLDERNAME,,
STARTSCRIPT/
ENDSCRIPT/

Exchange the red 'PCDCreateFolder' to 'CreateDir' if you want to use the 'smaller' script.

Jan d.
06-03-2008, 08:27 AM
Thanks for sharing. This has been an issue for me before. My solutions have been less elegant.


Jan.

vpt.se
06-03-2008, 11:53 AM
You are most welcome! Happy to have helped!