"deko" <ww*******************************@nospam.com> wrote in
news:Qf*******************@newssvr27.news.prodigy. com:
In a multi-user environment, I have a table that stores hyperlinks to
documents that are stored on the machine that hosts the mdb database.
The table entry looks like this:
ProductDescription.htm#file:\\DBHOST\C$\Documents and
Settings\Administrator\My
Documents\Products\Documents\ProductDescription.ht m
Having the hyperlink in this format allows the document to be opened
by anyone on the local area network.
The problem is when a remote user wants to add a document link - I
have a function that will populate the table with the above string,
but how do I copy the document to the DBHOST?
I've tried using FileCopy:
FileCopy C:\DirectoryonRemoteMachine\ProductDescription.htm
\\DBHOST\C$\Documents and Settings\Administrator\My
Documents\Products\Documents\ProductDescription.ht m
But that doesn't work.
Do I need to use the API here?
Private Declare Function CopyFile Lib "kernel32" _
( _
existingfile As String, _
newfile As String, _
failIfExists As Boolean _
)
It's safe to assume that a drive is mapped to the DBHOST - is there a
way to determine the drive letter and construct a target path that
way? Other options?
Thanks in advance.
If you're prepared to use Visual Basic Scripting, then this may help.
You'll need a Reference to the Scripting Library.
It's one of these on my Win98 Access97 machine.
C:\WINDOWS\SYSTEM\SCRRUN.DLL
C:\WINDOWS\SYSTEM\MSSCP.DLL
C:\WINDOWS\SYSTEM\WSHOM.OCX
(This may be Overkill, of course)
'Visual Basic Scripting Edition Language Reference
'FileSystemObjectSample Code
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' FileSystemObject Sample Code
' Copyright 1998 Microsoft Corporation. All Rights Reserved.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' Regarding code quality:
' 1) The following code does a lot of string manipulation by
' concatenating short strings together with the "&" operator.
' Since string concatenation is expensive, this is a very
' inefficient way to write code. However, it is a very
' maintainable way to write code, and is used here because this
' program performs extensive disk operations, and because the
' disk is much slower than the memory operations required to
' concatenate the strings. Keep in mind that this is demonstration
' code, not production code.
'
' 2) "Option Explicit" is used, because declared variable access is
' slightly faster than undeclared variable access. It also prevents
' bugs from creeping into your code, such as when you misspell
' DriveTypeCDROM as DriveTypeCDORM.
'
' 3) Error handling is absent from this code, to make the code more
' readable. Although precautions have been taken to ensure that the
' code will not error in common cases, file systems can be
' unpredictable. In production code, use On Error Resume Next and
' the Err object to trap possible errors.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' Some handy global variables
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Dim TabStop
Dim NewLine
Const TestDrive = "C"
Const TestFilePath = "C:\Test"
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' Constants returned by Drive.DriveType
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Const DriveTypeRemovable = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDisk = 5
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' Constants returned by File.Attributes
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Const FileAttrNormal = 0
Const FileAttrReadOnly = 1
Const FileAttrHidden = 2
Const FileAttrSystem = 4
Const FileAttrVolume = 8
Const FileAttrDirectory = 16
Const FileAttrArchive = 32
Const FileAttrAlias = 64
Const FileAttrCompressed = 128
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' Constants for opening files
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' ShowDriveType
' Purpose:
' Generates a string describing the drive type of a given Drive object.
' Demonstrates the following
' - Drive.DriveType
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function ShowDriveType(Drive)
Dim s
Select Case Drive.DriveType
Case DriveTypeRemovable
s = "Removable"
Case DriveTypeFixed
s = "Fixed"
Case DriveTypeNetwork
s = "Network"
Case DriveTypeCDROM
s = "CD-ROM"
Case DriveTypeRAMDisk
s = "RAM Disk"
Case Else
s = "Unknown"
End Select
ShowDriveType = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' ShowFileAttr
' Purpose:
' Generates a string describing the attributes of a file or folder.
' Demonstrates the following
' - File.Attributes
' - Folder.Attributes
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function ShowFileAttr(File) ' File can be a file or folder
Dim s
Dim Attr
Attr = File.Attributes
If Attr = 0 Then
ShowFileAttr = "Normal"
Exit Function
End If
If Attr And FileAttrDirectory Then s = s & "Directory "
If Attr And FileAttrReadOnly Then s = s & "Read-Only "
If Attr And FileAttrHidden Then s = s & "Hidden "
If Attr And FileAttrSystem Then s = s & "System "
If Attr And FileAttrVolume Then s = s & "Volume "
If Attr And FileAttrArchive Then s = s & "Archive "
If Attr And FileAttrAlias Then s = s & "Alias "
If Attr And FileAttrCompressed Then s = s & "Compressed "
ShowFileAttr = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' GenerateDriveInformation
' Purpose:
' Generates a string describing the current state of the
' available drives.
' Demonstrates the following
' - FileSystemObject.Drives
' - Iterating the Drives collection
' - Drives.Count
' - Drive.AvailableSpace
' - Drive.DriveLetter
' - Drive.DriveType
' - Drive.FileSystem
' - Drive.FreeSpace
' - Drive.IsReady
' - Drive.Path
' - Drive.SerialNumber
' - Drive.ShareName
' - Drive.TotalSize
' - Drive.VolumeName
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function GenerateDriveInformation(fso)
Dim Drives
Dim Drive
Dim s
Set Drives = fso.Drives
s = "Number of drives:" & TabStop & Drives.Count & NewLine & NewLine
' Construct 1st line of report.
s = s & String(2, TabStop) & "Drive"
s = s & String(3, TabStop) & "File"
s = s & TabStop & "Total"
s = s & TabStop & "Free"
s = s & TabStop & "Available"
s = s & TabStop & "Serial" & NewLine
' Construct 2nd line of report.
s = s & "Letter"
s = s & TabStop & "Path"
s = s & TabStop & "Type"
s = s & TabStop & "Ready?"
s = s & TabStop & "Name"
s = s & TabStop & "System"
s = s & TabStop & "Space"
s = s & TabStop & "Space"
s = s & TabStop & "Space"
s = s & TabStop & "Number" & NewLine
' Separator line.
s = s & String(105, "-") & NewLine
For Each Drive In Drives
s = s & Drive.DriveLetter
s = s & TabStop & Drive.path
s = s & TabStop & ShowDriveType(Drive)
s = s & TabStop & Drive.IsReady
If Drive.IsReady Then
If DriveTypeNetwork = Drive.DriveType Then
s = s & TabStop & Drive.ShareName
Else
s = s & TabStop & Drive.VolumeName
End If
s = s & TabStop & Drive.FileSystem
s = s & TabStop & Drive.TotalSize
s = s & TabStop & Drive.FreeSpace
s = s & TabStop & Drive.AvailableSpace
s = s & TabStop & Hex(Drive.SerialNumber)
End If
s = s & NewLine
Next
GenerateDriveInformation = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' GenerateFileInformation
' Purpose:
' Generates a string describing the current state of a file.
' Demonstrates the following
' - File.Path
' - File.Name
' - File.Type
' - File.DateCreated
' - File.DateLastAccessed
' - File.DateLastModified
' - File.Size
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function GenerateFileInformation(File)
Dim s
s = NewLine & "Path:" & TabStop & File.path
s = s & NewLine & "Name:" & TabStop & File.Name
s = s & NewLine & "Type:" & TabStop & File.Type
s = s & NewLine & "Attribs:" & TabStop & ShowFileAttr(File)
s = s & NewLine & "Created:" & TabStop & File.DateCreated
s = s & NewLine & "Accessed:" & TabStop & File.DateLastAccessed
s = s & NewLine & "Modified:" & TabStop & File.DateLastModified
s = s & NewLine & "Size" & TabStop & File.Size & NewLine
GenerateFileInformation = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' GenerateFolderInformation
' Purpose:
' Generates a string describing the current state of a folder.
' Demonstrates the following
' - Folder.Path
' - Folder.Name
' - Folder.DateCreated
' - Folder.DateLastAccessed
' - Folder.DateLastModified
' - Folder.Size
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function GenerateFolderInformation(Folder)
Dim s
s = "Path:" & TabStop & Folder.path
s = s & NewLine & "Name:" & TabStop & Folder.Name
s = s & NewLine & "Attribs:" & TabStop & ShowFileAttr(Folder)
s = s & NewLine & "Created:" & TabStop & Folder.DateCreated
s = s & NewLine & "Accessed:" & TabStop & Folder.DateLastAccessed
s = s & NewLine & "Modified:" & TabStop & Folder.DateLastModified
s = s & NewLine & "Size:" & TabStop & Folder.Size & NewLine
GenerateFolderInformation = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' GenerateAllFolderInformation
' Purpose:
' Generates a string describing the current state of a
' folder and all files and subfolders.
' Demonstrates the following
' - Folder.Path
' - Folder.SubFolders
' - Folders.Count
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function GenerateAllFolderInformation(Folder)
Dim s
Dim SubFolders
Dim SubFolder
Dim Files
Dim File
s = "Folder:" & TabStop & Folder.path & NewLine & NewLine
Set Files = Folder.Files
If 1 = Files.Count Then
s = s & "There is 1 file" & NewLine
Else
s = s & "There are " & Files.Count & " files" & NewLine
End If
If Files.Count <> 0 Then
For Each File In Files
s = s & GenerateFileInformation(File)
Next
End If
Set SubFolders = Folder.SubFolders
If 1 = SubFolders.Count Then
s = s & NewLine & "There is 1 sub folder" & NewLine & NewLine
Else
s = s & NewLine & "There are " & SubFolders.Count & " sub folders" _
& NewLine & NewLine
End If
If SubFolders.Count <> 0 Then
For Each SubFolder In SubFolders
s = s & GenerateFolderInformation(SubFolder)
Next
s = s & NewLine
For Each SubFolder In SubFolders
s = s & GenerateAllFolderInformation(SubFolder)
Next
End If
GenerateAllFolderInformation = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' GenerateTestInformation
' Purpose:
' Generates a string describing the current state of the C:\Test
' folder and all files and subfolders.
' Demonstrates the following
' - FileSystemObject.DriveExists
' - FileSystemObject.FolderExists
' - FileSystemObject.GetFolder
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function GenerateTestInformation(fso)
Dim TestFolder
Dim s
If Not fso.DriveExists(TestDrive) Then Exit Function
If Not fso.FolderExists(TestFilePath) Then Exit Function
Set TestFolder = fso.GetFolder(TestFilePath)
GenerateTestInformation = GenerateAllFolderInformation(TestFolder)
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' DeleteTestDirectory
' Purpose:
' Cleans up the test directory.
' Demonstrates the following
' - FileSystemObject.GetFolder
' - FileSystemObject.DeleteFile
' - FileSystemObject.DeleteFolder
' - Folder.Delete
' - File.Delete
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Sub DeleteTestDirectory(fso)
Dim TestFolder
Dim SubFolder
Dim File
' Two ways to delete a file:
fso.DeleteFile (TestFilePath & "\Beatles\OctopusGarden.txt")
Set File = fso.GetFile(TestFilePath & "\Beatles\BathroomWindow.txt")
File.Delete
' Two ways to delete a folder:
fso.DeleteFolder (TestFilePath & "\Beatles")
fso.DeleteFile (TestFilePath & "\ReadMe.txt")
Set TestFolder = fso.GetFolder(TestFilePath)
TestFolder.Delete
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' CreateLyrics
' Purpose:
' Builds a couple of text files in a folder.
' Demonstrates the following
' - FileSystemObject.CreateTextFile
' - TextStream.WriteLine
' - TextStream.Write
' - TextStream.WriteBlankLines
' - TextStream.Close
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Sub CreateLyrics(Folder)
Dim TextStream
Set TextStream = Folder.CreateTextFile("OctopusGarden.txt")
' Note that this does not add a line feed to the file.
TextStream.Write ("Octopus' Garden ")
TextStream.WriteLine ("(by Ringo Starr)")
TextStream.WriteBlankLines (1)
TextStream.WriteLine ("I'd like to be under the sea in an octopus'
garden in the shade,")
TextStream.WriteLine ("He'd let us in, knows where we've been -- in his
octopus' garden in the shade.")
TextStream.WriteBlankLines (2)
TextStream.Close
Set TextStream = Folder.CreateTextFile("BathroomWindow.txt")
TextStream.WriteLine ("She Came In Through The Bathroom Window (by
Lennon/McCartney)")
TextStream.WriteLine ("")
TextStream.WriteLine ("She came in through the bathroom window protected
by a silver spoon")
TextStream.WriteLine ("But now she sucks her thumb and wanders by the
banks of her own lagoon")
TextStream.WriteBlankLines (2)
TextStream.Close
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' GetLyrics
' Purpose:
' Displays the contents of the lyrics files.
' Demonstrates the following
' - FileSystemObject.OpenTextFile
' - FileSystemObject.GetFile
' - TextStream.ReadAll
' - TextStream.Close
' - File.OpenAsTextStream
' - TextStream.AtEndOfStream
' - TextStream.ReadLine
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function GetLyrics(fso)
Dim TextStream
Dim s
Dim File
' There are several ways to open a text file, and several
' ways to read the data out of a file. Here's two ways
' to do each:
Set TextStream = fso.OpenTextFile(TestFilePath &
"\Beatles\OctopusGarden.txt", OpenFileForReading)
s = TextStream.readAll & NewLine & NewLine
TextStream.Close
Set File = fso.GetFile(TestFilePath & "\Beatles\BathroomWindow.txt")
Set TextStream = File.OpenAsTextStream(OpenFileForReading)
Do While Not TextStream.AtEndOfStream
s = s & TextStream.ReadLine & NewLine
Loop
TextStream.Close
GetLyrics = s
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' BuildTestDirectory
' Purpose:
' Builds a directory hierarchy to demonstrate the FileSystemObject.
' We'll build a hierarchy in this order:
' C:\Test
' C:\Test\ReadMe.txt
' C:\Test\Beatles
' C:\Test\Beatles\OctopusGarden.txt
' C:\Test\Beatles\BathroomWindow.txt
' Demonstrates the following
' - FileSystemObject.DriveExists
' - FileSystemObject.FolderExists
' - FileSystemObject.CreateFolder
' - FileSystemObject.CreateTextFile
' - Folders.Add
' - Folder.CreateTextFile
' - TextStream.WriteLine
' - TextStream.Close
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function BuildTestDirectory(fso)
Dim TestFolder
Dim SubFolders
Dim SubFolder
Dim TextStream
' Bail out if (a) the drive does not exist, or if (b) the directory is
being built
' already exists.
If Not fso.DriveExists(TestDrive) Then
BuildTestDirectory = False
Exit Function
End If
If fso.FolderExists(TestFilePath) Then
BuildTestDirectory = False
Exit Function
End If
Set TestFolder = fso.CreateFolder(TestFilePath)
Set TextStream = fso.CreateTextFile(TestFilePath & "\ReadMe.txt")
TextStream.WriteLine ("My song lyrics collection")
TextStream.Close
Set SubFolders = TestFolder.SubFolders
Set SubFolder = SubFolders.Add("Beatles")
CreateLyrics SubFolder
BuildTestDirectory = True
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' The main routine
' First, it creates a test directory, along with some subfolders
' and files. Then, it dumps some information about the available
' disk drives and about the test directory, and then cleans
' everything up again.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Sub Main()
Dim fso
' Set up global data.
TabStop = Chr(9)
NewLine = Chr(10)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not BuildTestDirectory(fso) Then
MsgBox "Test directory already exists or cannot be created. Cannot
continue."
Exit Sub
End If
MsgBox GenerateDriveInformation(fso) & NewLine & NewLine
MsgBox GenerateTestInformation(fso) & NewLine & NewLine
MsgBox GetLyrics(fso) & NewLine & NewLine
DeleteTestDirectory fso
End Sub
<
www.clearpointsystems.com