2

I need to create vbscript which will create new folder 'test' and subfolder 'Output'.There is already a folder structure C:\Documents and Settings\All Users\Application Data\Fmwire,I need to create test\Output under those structure

I have created vbscript like this but i am getting error like this

Error: Path not found Code: 800A004C Source: Microsoft VBScript runtime error

Const OSCPATH = "\Fmwire\test\Output"
Const ALL_USERS_APPLICATION_DATA = &H23&

Dim fso                 ' File System Object
Dim objApplication      ' Application object
Dim objFolder           ' Folder object
Dim objFolderItem       ' FolderItem object
Dim fname               ' Path to Settings folder 






                Set objApplication  = CreateObject("Shell.Application")
                Set objFolder = objApplication.Namespace(ALL_USERS_APPLICATION_DATA)
                Set objFolderItem = objFolder.Self
                fname = objFolderItem.Path & OSCPATH

                Set fso = CreateObject("Scripting.FileSystemObject")
                If fso.FolderExists(fname) Then
                Set objFolder = fso.GetFolder(fname)
                Else
                Set objFolder = fso.CreateFolder(fname)
                   If Err Then
                     Err.Clear
                      strErr = SPOFOLDERFAIL
                      rCode = 4
                   End If
                End If

What changes i have to do for correcting this

1
  • It might be an ACL issue. Anyone can create Artifacts created under All users application data profile, but they will be not be writeable by any other user unless that user (or an admin) specifically removes the access restrictions so that anyone can modify items. Check existing permissions on that target folder. Commented Apr 20, 2011 at 12:13

1 Answer 1

7
Const OSCPATH = "\Fmwire\test\Output"
Const ALL_USERS_APPLICATION_DATA = &H23&

Set objApplication  = CreateObject("Shell.Application")
Set objFolder = objApplication.Namespace(ALL_USERS_APPLICATION_DATA)
Set objFolderItem = objFolder.Self
fname = objFolderItem.Path

Set fso = CreateObject("Scripting.FileSystemObject")
folders = Split(OSCPATH, "\")
For i = 0 To UBound(folders)
    fname = fso.BuildPath(fname, folders(i))
    If fso.FolderExists(fname) Then
        Set objFolder = fso.GetFolder(fname)
    Else
        Set objFolder = fso.CreateFolder(fname)
       If Err Then
         Err.Clear
          strErr = SPOFOLDERFAIL
          rCode = 4
       End If
    End If
Next
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks its working ,,what was the issue,,i am new to vbscript
You need to explicitly create each folder level that doesn't already exist (i.e., test, then test\Output).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.