Solved

Create Directories from List

Posted on 2004-04-27
5
329 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

708 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

14 Experts available now in Live!

Get 1:1 Help Now