473,379 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Checking if a Folder Exists and if not, creating it.

Hi,

I'm afraid this will no doubt horrendously basic as I'm a complete newbie to VB and have dived in without learning to do much... Start in the deep end and all.

So if anyone could help, I'd appreciate it;

I've got this bit of code and I couldn't for the life of me tell you why it doesn't work, if anyone else can I'd appreciate it!

Cheers

----------------

Sub Folders()

Directory1
Directory2

End Sub

Sub Directory1()

Application.ScreenUpdating = False

Worksheets("Summary").Activate

Dim cli As String
Dim Job As String

cli = Cells(6, 5).Value
Job = Cells(1, 29).Value

Dim FSO, Folder
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Folder = "\\Work\trial reports\" & cli & " \ "
If FSO.FolderExists(Folder) Then

MsgBox "Client folder exists, creating job folder for certificate"

Else

MkDir "\\Work\Trial reports\" & cli & "\"

End If

End Sub

Sub Directory2()

Application.ScreenUpdating = False

Worksheets("Summary").Activate

Dim cli As String
Dim Job As String

cli = Cells(6, 5).Value
Job = Cells(1, 29).Value

Dim FSO, File
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
File = "\\Work\Trial reports\" & cli & "\" & Job & "\"
If FSO.FolderExists(File) Then

MsgBox "Job folder exists, please save certificate when complete"

Else

MkDir "\\Work\Trial reports\" & cli & "\" & Job & "\"

End If

End Sub

----------------

Thanks again!

Ben
Jan 8 '07 #1
2 6867
seshu
156 100+
hi this is seshu
i have a piece of code here but in project refrences you need to add file system object with name microsoft scripting runtime object

on button click event
Dim fsys As New FileSystemObject
dim str as string
str="path"
if fsys.folderexists(str) then
msgbox"folder exists"
else
fsys.createfolder"path of the folder to be created"\new folder name
msgbox "folder created"
end if
end sub
Jan 9 '07 #2
Killer42
8,435 Expert 8TB
I've got this bit of code and I couldn't for the life of me tell you why it doesn't work, if anyone else can I'd appreciate it!
Welcome to TheScripts!

Could you give us some idea of what result you do get? "Doesn't work" is awfully vague.
Jan 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
2
by: Bryan Rasmussen | last post by:
Hi I have a little program that is importing from os.path import exists, join, isdir, normpath, isfile at one point in my program I check if a file exists using if exists("c:\projects"): and...
3
by: Rob Meade | last post by:
Hi all, I am allowing a user to create a directory within my application. I have them entering the name for the directory in a form. When the form is processed I initially check for any...
0
by: Joe | last post by:
I've been running into problems when trying to create a Virtual FTP folder in ASP.Net. I've tried it a few ways but none of them has worked so far. I have identity impersonation turned on, and the...
5
by: BerkshireGuy | last post by:
Hello everyone, I have a bond form that a user uses to enter data. One of my fields, is PolicyNumber. I added some code on the Before Update event of txtPolicyNumber that checks to see if...
2
by: Brian Henry | last post by:
How with out creating a COM object, do you check in .NET to see if a folder exists? I found the check for a file but i need to check for a folder, and there does not seem to be on in the path class
1
by: RSH | last post by:
I'm creating databases programatically in .Net and I want to verify that the database doesn't exist before creating it. i found the SQL code: IF NOT EXISTS(SELECT * FROM <databasename>) But...
2
by: patelxxx | last post by:
Checking the folder before actually creating the new folder . Can someone guide me in what 'Checks' do I need to do before I create a new folder? I know that one of the checks will be to see if...
4
by: ndedhia1 | last post by:
Hi. I am writing a java program in which I want to ftp a file to another unix box. First I have to check if the directory exists in which I am ftping into and if it does not exist, I have to create...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.