PC Review


Reply
Thread Tools Rate Thread

Check if specifik folder exist.

 
 
HH
Guest
Posts: n/a
 
      29th Nov 2006
Hi'

I have a macro copying files to specifik folders. I only have one
problem, if the folder is not created then the script stops.


How do I let the script ignore this file and just move on to the next?
I
suppose i need to check if the destination folder exist, but how?


Thanks

 
Reply With Quote
 
 
 
 
WhytheQ
Guest
Posts: n/a
 
      29th Nov 2006
an old post by Bob Philips says:

'################################
1. Use DIR to test, and FileSystemObject to create it


Dim myDir, myFile


myFile = "C:\Billing\Invoices\SepInv\"
myDir = Dir(myFile)
If myDir <> "" Then
MsgBox "Directory already exists"
Else
myDir =
CreateObject("Scripting.FileSystemObject").createFolder(myFile)
End If


2. Use FileSystemObject for both


Dim myDir, myFile


myFile = "C:\Billing\Invoices\SepInv\"
myDir =
CreateObject("Scripting.FileSystemObject").FolderExists(myFile)
If myDir = True Then
MsgBox "Directory already exists"
Else
myDir =
CreateObject("Scripting.FileSystemObject").createFolder(myFile)
End If
'#######################################

I'm sure the above must help
Rgds
J


On 29 Nov, 12:41, "HH" <j...@mail2hansen.dk> wrote:
> Hi'
>
> I have a macro copying files to specifik folders. I only have one
> problem, if the folder is not created then the script stops.
>
> How do I let the script ignore this file and just move on to the next?
> I
> suppose i need to check if the destination folder exist, but how?
>
> Thanks


 
Reply With Quote
 
MichDenis
Guest
Posts: n/a
 
      29th Nov 2006
| myFile = "C:\Billing\Invoices\SepInv\"
| myDir = Dir(myFile)
| If myDir <> "" Then
| MsgBox "Directory already exists"

This does not work if the folder is empty...

It's better if you use this : myDir = Dir(myFile, vbDirectory)



"WhytheQ" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
an old post by Bob Philips says:

'################################
1. Use DIR to test, and FileSystemObject to create it


Dim myDir, myFile


myFile = "C:\Billing\Invoices\SepInv\"
myDir = Dir(myFile)
If myDir <> "" Then
MsgBox "Directory already exists"
Else
myDir =
CreateObject("Scripting.FileSystemObject").createFolder(myFile)
End If


2. Use FileSystemObject for both


Dim myDir, myFile


myFile = "C:\Billing\Invoices\SepInv\"
myDir =
CreateObject("Scripting.FileSystemObject").FolderExists(myFile)
If myDir = True Then
MsgBox "Directory already exists"
Else
myDir =
CreateObject("Scripting.FileSystemObject").createFolder(myFile)
End If
'#######################################

I'm sure the above must help
Rgds
J


On 29 Nov, 12:41, "HH" <j...@mail2hansen.dk> wrote:
> Hi'
>
> I have a macro copying files to specifik folders. I only have one
> problem, if the folder is not created then the script stops.
>
> How do I let the script ignore this file and just move on to the next?
> I
> suppose i need to check if the destination folder exist, but how?
>
> Thanks




 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      29th Nov 2006
Use code like the following:

Dim FolderExists As Boolean
Dim FolderName As String
FolderName = "C:\Test1234"
FolderExists = (Dir(FolderName, vbDirectory + vbHidden) <> vbNullString)
If FolderExists = False Then
'''''''''''''''''''''''''''''''''''
' If the folder doesn't exist, use
' MkDir to create the folder.
'''''''''''''''''''''''''''''''''''
On Error Resume Next
Err.Clear
MkDir FolderName
If Err.Number <> 0 Then
MsgBox "An error occurred with MkDir:" & vbCrLf & _
"Err: " & CStr(Err.Number) & vbCrLf & _
"Desc: " & Err.Description
End If
On Error GoTo 0
End If

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"MichDenis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>| myFile = "C:\Billing\Invoices\SepInv\"
> | myDir = Dir(myFile)
> | If myDir <> "" Then
> | MsgBox "Directory already exists"
>
> This does not work if the folder is empty...
>
> It's better if you use this : myDir = Dir(myFile, vbDirectory)
>
>
>
> "WhytheQ" <(E-Mail Removed)> a écrit dans le message de news:
> (E-Mail Removed)...
> an old post by Bob Philips says:
>
> '################################
> 1. Use DIR to test, and FileSystemObject to create it
>
>
> Dim myDir, myFile
>
>
> myFile = "C:\Billing\Invoices\SepInv\"
> myDir = Dir(myFile)
> If myDir <> "" Then
> MsgBox "Directory already exists"
> Else
> myDir =
> CreateObject("Scripting.FileSystemObject").createFolder(myFile)
> End If
>
>
> 2. Use FileSystemObject for both
>
>
> Dim myDir, myFile
>
>
> myFile = "C:\Billing\Invoices\SepInv\"
> myDir =
> CreateObject("Scripting.FileSystemObject").FolderExists(myFile)
> If myDir = True Then
> MsgBox "Directory already exists"
> Else
> myDir =
> CreateObject("Scripting.FileSystemObject").createFolder(myFile)
> End If
> '#######################################
>
> I'm sure the above must help
> Rgds
> J
>
>
> On 29 Nov, 12:41, "HH" <j...@mail2hansen.dk> wrote:
>> Hi'
>>
>> I have a macro copying files to specifik folders. I only have one
>> problem, if the folder is not created then the script stops.
>>
>> How do I let the script ignore this file and just move on to the next?
>> I
>> suppose i need to check if the destination folder exist, but how?
>>
>> Thanks

>
>
>



 
Reply With Quote
 
HH
Guest
Posts: n/a
 
      5th Dec 2006

Thanks - its working now.

HH

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if folder exist? Vsn Microsoft Access Queries 1 14th Jun 2006 10:49 AM
Check if a folder exist loopoo Microsoft Excel Programming 5 7th Dec 2005 12:07 PM
How to: check if folder exist, if not, create escorido Microsoft Excel Programming 2 9th Jul 2004 01:28 PM
How to check if a folder/directory exist using VBA wellie Microsoft Excel Programming 1 1st Mar 2004 02:24 AM
Check if folder exist =?iso-8859-1?B?SmF5qQ==?= Microsoft Outlook VBA Programming 0 25th Sep 2003 09:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:32 AM.