FSO.FolderExists doesn't recognize a valid path

kevin_n_pa

New Member
Joined
Dec 25, 2017
Messages
3
I wrote a program to input a CSV file, slice and dice the data and output a report. The program prompts the user to select a specific CSV file from the files in a fixed folder. The program then saves the file to C:\temp. The program also saves a copy of a schema.ini file from a separate fixed folder (no user prompt) to the same C-drive folder. The code includes checks to verify the paths of the two source folders and the existence of the schema.ini file.

The program verifies the path to the C-drive folder; no problem. But it doesn't recognize the path to the folder containing the schema.ini file. I've checked and double checked the code and the path names.

I found a solution by using the FolderExists method and Application.FileDialog(msoFileDialogFolderPicker) and looping through the verification. The program recognizes the path the second time. It's not elegant. But it seems to solve the problem.

I would prefer to find the root cause of the problem and correction I can trust. Note: The problem path is located on an Intranet. Not sure if this matters.

Any help would be greatly appreciated. Thank you.


Kevin

Code:
[COLOR=#333333]Dim FSO As Scripting.FileSystemObject[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Dim fdl As FileDialog
Dim i As Integer

    Set FSO = New Scripting.FileSystemObject

    i = 1
Cdrive_2ndCheck:
    If i > 2 Then
        MsgBox "The path " & """" & CSVDestinationFolder & """" & " cannot be verified." & _
                Chr(10) & Chr(10) & _
                "The program will be stopped. No report will be created."
        GoTo EndProgram
    End If
    ' verify path to CSV file temporary location
    If FSO.FolderExists(CSVDestinationFolder & "\") = False Then
        Set fdl = Application.FileDialog(msoFileDialogFolderPicker)
        fdl.InitialFileName = CSVDestinationFolder & "\"
        Set fdl = Nothing
        i = i + 1
        GoTo Cdrive_2ndCheck
    End If

    ' verify if SCHEMA.INI exists
    Application.StatusBar = "Copying schema.ini file to temporary location..."
    If VerifyFileExists(CSVDestinationFolder & "\" & SchemaINIfilename) = False Then
        i = 1
SchemaINI_2ndCheck:
        If i > 2 Then
            MsgBox "The path to the location of " & """" & "schema.ini" & """" & " cannot be verified." & _
                    Chr(10) & Chr(10) & _
                    "The program will be stopped. No report will be created."
            GoTo EndProgram
        End If
        ' verify path to source location of schema.ini
        If FSO.FolderExists(SchemaINIpath & "\") = False Then ' path and/or file cannot be verified
            Set fdl = Application.FileDialog(msoFileDialogFolderPicker)
            fdl.InitialFileName = SchemaINIpath & "\"
            Set fdl = Nothing
            i = i + 1
            GoTo SchemaINI_2ndCheck
        Else
            ' path is verified and file exists in the folder
            If VerifyFileExists(CSVDestinationFolder & "\" & SchemaINIfilename) = False Then
                FileCopy SchemaINIpath & "\" & SchemaINIfilename, CSVDestinationFolder & "\" & SchemaINIfilename
            End If
        End If </code>[COLOR=#333333]    End If[/COLOR]

 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top