Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Making a folder using VB


Recommended Posts

can someone tell me why this will not work

code:

 If Not FSO.FolderExists("WaikikiMSPrograms" &companyname) Then 

Call FSO.CreateFolder("WaikikiMSPrograms" &companyname)

It is suppost to look and see if there is a company name like the one you type in at a prompt, but it just puts another folder with the same name. It doesn't even pop up and tell me that there is a folder already with the same name.

 

it use to be

code:

If Not FSO.FolderExists("C:WORK" &companyname) Then 

Call FSO.CreateFolder("C:WORK" &companyname)

and it worked fine. when I tried to change it to work on network it started happening???

Link to comment
Share on other sites

Ok, FileSystemObject does support UNC paths just fine. I wrote this to test:

 

code:

Const DEF_PATH = "REMOTECOMPUTERSome FolderChris"

Const DEF_DPATH = "connormac"

Const DEF_FNAME = "Test.txt"

Const DEF_FSO_READ = 1

 

Call Main()

 

Sub Main()

Dim objFSO

Dim objTS

Dim objNewFolder

 

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' Can we access UNC paths?

If objFSO.FolderExists(DEF_PATH) Then

ShowString "Yup, it's here"

Else

ShowString "Nope"

End If

 

' Can we create new directories using UNC paths?

Set objNewFolder = objFSO.CreateFolder(DEF_PATH & "" & DEF_DPATH)

 

If (objNewFolder Is Nothing) Then ShowString "We can create that directory here"

 

' Can we read files using UNC paths?

Set objTS = objFSO.OpenTextFile(DEF_PATH & "" & DEF_FNAME, DEF_FSO_READ, False)

 

Do While(objTS.AtEndOfStream <> True)

strTempLine = Trim(objTS.ReadLine)

 

ShowString "From the file: " & strTempLine

Loop

 

Set objFSO = Nothing

Set objTS = Nothing

 

ShowString "Done!"

End Sub

The next thing I'd ask is...do you have permission to create directories in that network location?

Link to comment
Share on other sites

Bullins,

Changed

 

If Not FSO.FolderExists("WaikikiMSPrograms" &companyname) Then

Call FSO.CreateFolder("WaikikiMSPrograms" &companyname)

 

to

 

If Not FSO.FolderExists("F:" &companyname) Then

Call FSO.CreateFolder("F:" &companyname)

 

It does the same thing. creates a new folder.

But if I create a folder "TEST" using the VB. Then create the folder "TEST" again it works right. It is like it is not looking at the folders that were already created on the network???

Link to comment
Share on other sites

quote:

It does the same thing. creates a new folder.

But if I create a folder "TEST" using the VB. Then create the folder "TEST" again it works right. It is like it is not looking at the folders that were already created on the network???


Huh? headscratch.gif

 

Maybe give me an example with full paths that you want/will be using. Then we'll get this all sorted out wink.gif

Link to comment
Share on other sites

'////////////////////////////////////////////////////////////////////////////////

'//

'// Author: Mick George [email protected]

'// Date: 16/09/2003 12:58 PM

'// File Name: Creat MS Folfer.VBS

'//

'// Description: Creat MS Folder

'//

'// Comments: '////////////////////////////////////////////////////////////////////////////////

'//

'// Author: Mick George [email protected]

'// Date: 16/09/2003 12:58 PM

'// File Name: Creat MS Folfer.VBS

'//

'// Description: Creat MS Folder

'//

'// Comments:

'//

'////////////////////////////////////////////////////////////////////////////////

 

 

'///////////////// My Constants /////////////////

 

 

'///////////////// My Global Variables //////////

 

 

' -- Start Script

Call Main()

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

On Error Resume Next

 

 

Dim companyname

Dim Program

 

Do 'ask until a real company name is entered

companyname=AskString("Company Name?")

Loop While companyname="Company Name?" Or companyname="((ESC))" Or companyname=""

 

Do 'ask until a real program number is used

Program=AskString("Part number?")

Loop While Program="Part number?" Or Program="" Or Program="((ESC))"

 

 

If Not MakeFolders(companyname, Program) Then

ShowString "Failed to create folders, aborting script"

Exit Sub

End If

 

 

End Sub

 

' ////////////////////

' Function Declaration

' ////////////////////

 

Public Function MakeFolders(companyname, Program)

 

On Error Resume Next

 

' -- Check to see if folders exist

Dim FSO

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

'

' -- This is kinda long winded but does the job

' -- NOTE: If you use an invalid character for a part number you'll have a problem!

 

If Not FSO.FolderExists("F:" &companyname) Then

Call FSO.CreateFolder("F:" &companyname)

End If

 

If Not FSO.FolderExists("F:" &companyname & "" & Program) Then

Call FSO.CreateFolder("F:" &companyname & "" & Program)

End If

 

If Err Then

MakeFolders = False

Else

MakeFolders = True

End If

Link to comment
Share on other sites

Right. So in the case of a company already being there, do you end up in the code block that tries to create the folder?

 

code:

If Not FSO.FolderExists("WaikikiMSPrograms" & companyname) Then

ShowString "If the path to this company's folder already exists, you should not see this message."

FSO.CreateFolder("WaikikiMSPrograms" & companyname)

End If

Link to comment
Share on other sites

So let me get this straight. If you have a folder that already exists called:

 

WaikikiMSProgramsAcme

 

And then the script gets to here:

 

code:

' In this example, the companyname variable contains a value "Acme"

 

 

If Not FSO.FolderExists("WaikikiMSPrograms" & companyname) Then

ShowString "If the path to this company's folder already exists, you should not see this message."

FSO.CreateFolder("WaikikiMSPrograms" & companyname)

End If

It creates a folder called:

 

WaikikiMSProgramsAcmeAcme

 

Am I understanding it right?

Link to comment
Share on other sites

quote:

but it does look like there is a space in front of the folder name I create with the VB. maybe it is the space??? if so how do I get rid of the space


To get rid of leading and trailing spaces in a string, use the Trim() function. So for example:

 

code:

Do 'ask until a real program number is used

Program=Trim(AskString("Part number?"))

Loop While Program="Part number?" Or Program="" Or Program="((ESC))"

Better?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...