Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Why the file is saved in the different locations?

I have the code as following to convert a DAT file to a TXT file,
----------------
Sub DataImport(strPath As String, strTableName As String)
'Variables used to create and modify the file extension
Dim objFileSystem
Dim objFile
Dim strFileCopy As String
Dim intExtPosition As Integer

'Create an instance of the FileSystemObject to access
'the local file system
Set objFileSystem = CreateObject("Scripting.FileSystemObject")

'Use the GetFile method to return a File object corresponding to the
'file in a specified path.
Set objFile = objFileSystem.GetFile(strPath)
intExtPosition = InStr(objFile.Name, ".")
If intExtPosition > 0 Then
strFileCopy = Left(objFile.Name, intExtPosition - 1) & ".txt"
Else
strFileCopy = objFile.Name & ".txt"
End If

'Create a copy of the file with a .txt extension
objFile.Copy strFileCopy, True
'DoCmd.TransferText acImportDelim, , strTableName, strFileCopy, True
End Sub
------------
The code is straightforward, but I don't understand why sometimes, when I run the code, the copy text file is saved in my current working directory (D:\VB6.0\Myfile.txt), and other times it is saved C:\MyDocument\Myfile.txt) ?
Can you tell my why and how to "force" it to be saved only in one specific location?
Thank you,
Curie
[1507 byte] By [curie] at [2007-11-11 6:39:29]
# 1 Re: Why the file is saved in the different locations?
If you want it saved in a specific folder, you must include the path in your strFileCopy variable.
Phil Weber at 2007-11-11 17:28:06 >
# 2 Re: Why the file is saved in the different locations?
If you start VB from the start menu or a desktop icon the program is launched from its installation folder and any files created within your code will be saved to that folder ("C:\Program Files\Microsoft Visual Studio\VB98" on my PC) unless you specify an explicit path.
Similarly, if you start VB by double clicking a project file the default folder your code will use is the location of the project file.
You can verify this by puttingDebug.Print CurDirin your startup form.
TrevorG at 2007-11-11 17:29:09 >