Solved

Create Directories from List

Posted on 2004-04-27
5
330 Views
Last Modified: 2010-08-05
I am trying to create directories from a list in excel

In vba I need the syntax to check if a directory exists & also the syntax to create a directory

Looking forward
0
Comment
Question by:smaill
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
wolfking earned 250 total points
ID: 10928565
Dir Function Example
This example uses the Dir function to check if certain files and directories exist. On the Macintosh, “HD:” is the default drive name and portions of the pathname are separated by colons instead of backslashes. Also, the Microsoft Windows wildcard characters are treated as valid file-name characters on the Mac. However, you can use the MacID function to specify file groups.

Dim MyFile, MyPath, MyName
' Returns "WIN.INI" (on Microsoft Windows) if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")    

' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")

' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir

' Return first *.TXT file with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)

' Display the names in C:\ that represent directories.
MyPath = "c:\"    ' Set the path.
MyName = Dir(MyPath, vbDirectory)    ' Retrieve the first entry.
Do While MyName <> ""    ' Start the loop.
    ' Ignore the current directory and the encompassing directory.
    If MyName <> "." And MyName <> ".." Then
        ' Use bitwise comparison to make sure MyName is a directory.
        If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
            Debug.Print MyName    ' Display entry only if it
        End If    ' it represents a directory.
    End If
    MyName = Dir    ' Get next entry.
Loop




MkDir path

The required path argument is a string expression that identifies the directory or folder to be created. The path may include the drive. If no drive is specified, MkDir creates the new directory or folder on the current drive.
0
 
LVL 1

Expert Comment

by:wolfking
ID: 10928591
MkDir Statement Example
This example uses the MkDir statement to create a directory or folder. If the drive is not specified, the new directory or folder is created on the current drive.

MkDir "MYDIR"    ' Make new directory or folder.

0
 
LVL 4

Assisted Solution

by:JpmSoft
JpmSoft earned 250 total points
ID: 10930853
1.- Open the VBA editor and add a reference to Microsoft Scripting Runtime
2.- Declare a FileSystemObject object:
        Dim FSO As New FileSystemObject
3.- For I=0 To LastRowOfList
   If Not FSO.FolderExist(oSheet.Cells(I,1)) Then
       FSO.CreateFolder oSheet.Cells(I,1)
   End If
Next I
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now