"deko" <ww************ *************** ****@nospam.com > wrote in
news:Qf******** ***********@new ssvr27.news.pro digy.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:
ProductDescript ion.htm#file:\\ DBHOST\C$\Docum ents and
Settings\Admini strator\My
Documents\Produ cts\Documents\P roductDescripti on.htm
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:\DirectoryonR emoteMachine\Pr oductDescriptio n.htm
\\DBHOST\C$\Doc uments and Settings\Admini strator\My
Documents\Produ cts\Documents\P roductDescripti on.htm
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\SYST EM\SCRRUN.DLL
C:\WINDOWS\SYST EM\MSSCP.DLL
C:\WINDOWS\SYST EM\WSHOM.OCX
(This may be Overkill, of course)
'Visual Basic Scripting Edition Language Reference
'FileSystemObje ctSample Code
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' FileSystemObjec t 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 DriveTypeRemova ble = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwor k = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDis k = 5
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' Constants returned by File.Attributes
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Const FileAttrNormal = 0
Const FileAttrReadOnl y = 1
Const FileAttrHidden = 2
Const FileAttrSystem = 4
Const FileAttrVolume = 8
Const FileAttrDirecto ry = 16
Const FileAttrArchive = 32
Const FileAttrAlias = 64
Const FileAttrCompres sed = 128
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' Constants for opening files
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Const OpenFileForRead ing = 1
Const OpenFileForWrit ing = 2
Const OpenFileForAppe nding = 8
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' ShowDriveType
' Purpose:
' Generates a string describing the drive type of a given Drive object.
' Demonstrates the following
' - Drive.DriveType
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function ShowDriveType(D rive)
Dim s
Select Case Drive.DriveType
Case DriveTypeRemova ble
s = "Removable"
Case DriveTypeFixed
s = "Fixed"
Case DriveTypeNetwor k
s = "Network"
Case DriveTypeCDROM
s = "CD-ROM"
Case DriveTypeRAMDis k
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.Attribut es
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function ShowFileAttr(Fi le) ' 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 FileAttrDirecto ry Then s = s & "Directory "
If Attr And FileAttrReadOnl y 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 FileAttrCompres sed Then s = s & "Compressed "
ShowFileAttr = s
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' GenerateDriveIn formation
' Purpose:
' Generates a string describing the current state of the
' available drives.
' Demonstrates the following
' - FileSystemObjec t.Drives
' - Iterating the Drives collection
' - Drives.Count
' - Drive.Available Space
' - Drive.DriveLett er
' - Drive.DriveType
' - Drive.FileSyste m
' - Drive.FreeSpace
' - Drive.IsReady
' - Drive.Path
' - Drive.SerialNum ber
' - Drive.ShareName
' - Drive.TotalSize
' - Drive.VolumeNam e
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function GenerateDriveIn formation(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.DriveLett er
s = s & TabStop & Drive.path
s = s & TabStop & ShowDriveType(D rive)
s = s & TabStop & Drive.IsReady
If Drive.IsReady Then
If DriveTypeNetwor k = Drive.DriveType Then
s = s & TabStop & Drive.ShareName
Else
s = s & TabStop & Drive.VolumeNam e
End If
s = s & TabStop & Drive.FileSyste m
s = s & TabStop & Drive.TotalSize
s = s & TabStop & Drive.FreeSpace
s = s & TabStop & Drive.Available Space
s = s & TabStop & Hex(Drive.Seria lNumber)
End If
s = s & NewLine
Next
GenerateDriveIn formation = s
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' GenerateFileInf ormation
' Purpose:
' Generates a string describing the current state of a file.
' Demonstrates the following
' - File.Path
' - File.Name
' - File.Type
' - File.DateCreate d
' - File.DateLastAc cessed
' - File.DateLastMo dified
' - File.Size
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function GenerateFileInf ormation(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(Fi le)
s = s & NewLine & "Created:" & TabStop & File.DateCreate d
s = s & NewLine & "Accessed:" & TabStop & File.DateLastAc cessed
s = s & NewLine & "Modified:" & TabStop & File.DateLastMo dified
s = s & NewLine & "Size" & TabStop & File.Size & NewLine
GenerateFileInf ormation = s
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' GenerateFolderI nformation
' Purpose:
' Generates a string describing the current state of a folder.
' Demonstrates the following
' - Folder.Path
' - Folder.Name
' - Folder.DateCrea ted
' - Folder.DateLast Accessed
' - Folder.DateLast Modified
' - Folder.Size
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function GenerateFolderI nformation(Fold er)
Dim s
s = "Path:" & TabStop & Folder.path
s = s & NewLine & "Name:" & TabStop & Folder.Name
s = s & NewLine & "Attribs:" & TabStop & ShowFileAttr(Fo lder)
s = s & NewLine & "Created:" & TabStop & Folder.DateCrea ted
s = s & NewLine & "Accessed:" & TabStop & Folder.DateLast Accessed
s = s & NewLine & "Modified:" & TabStop & Folder.DateLast Modified
s = s & NewLine & "Size:" & TabStop & Folder.Size & NewLine
GenerateFolderI nformation = s
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' GenerateAllFold erInformation
' Purpose:
' Generates a string describing the current state of a
' folder and all files and subfolders.
' Demonstrates the following
' - Folder.Path
' - Folder.SubFolde rs
' - Folders.Count
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function GenerateAllFold erInformation(F older)
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 & GenerateFileInf ormation(File)
Next
End If
Set SubFolders = Folder.SubFolde rs
If 1 = SubFolders.Coun t Then
s = s & NewLine & "There is 1 sub folder" & NewLine & NewLine
Else
s = s & NewLine & "There are " & SubFolders.Coun t & " sub folders" _
& NewLine & NewLine
End If
If SubFolders.Coun t <> 0 Then
For Each SubFolder In SubFolders
s = s & GenerateFolderI nformation(SubF older)
Next
s = s & NewLine
For Each SubFolder In SubFolders
s = s & GenerateAllFold erInformation(S ubFolder)
Next
End If
GenerateAllFold erInformation = s
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' GenerateTestInf ormation
' Purpose:
' Generates a string describing the current state of the C:\Test
' folder and all files and subfolders.
' Demonstrates the following
' - FileSystemObjec t.DriveExists
' - FileSystemObjec t.FolderExists
' - FileSystemObjec t.GetFolder
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function GenerateTestInf ormation(fso)
Dim TestFolder
Dim s
If Not fso.DriveExists (TestDrive) Then Exit Function
If Not fso.FolderExist s(TestFilePath) Then Exit Function
Set TestFolder = fso.GetFolder(T estFilePath)
GenerateTestInf ormation = GenerateAllFold erInformation(T estFolder)
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' DeleteTestDirec tory
' Purpose:
' Cleans up the test directory.
' Demonstrates the following
' - FileSystemObjec t.GetFolder
' - FileSystemObjec t.DeleteFile
' - FileSystemObjec t.DeleteFolder
' - Folder.Delete
' - File.Delete
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Sub DeleteTestDirec tory(fso)
Dim TestFolder
Dim SubFolder
Dim File
' Two ways to delete a file:
fso.DeleteFile (TestFilePath & "\Beatles\Octop usGarden.txt")
Set File = fso.GetFile(Tes tFilePath & "\Beatles\Bathr oomWindow.txt")
File.Delete
' Two ways to delete a folder:
fso.DeleteFolde r (TestFilePath & "\Beatles")
fso.DeleteFile (TestFilePath & "\ReadMe.tx t")
Set TestFolder = fso.GetFolder(T estFilePath)
TestFolder.Dele te
End Sub
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' CreateLyrics
' Purpose:
' Builds a couple of text files in a folder.
' Demonstrates the following
' - FileSystemObjec t.CreateTextFil e
' - TextStream.Writ eLine
' - TextStream.Writ e
' - TextStream.Writ eBlankLines
' - TextStream.Clos e
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Sub CreateLyrics(Fo lder)
Dim TextStream
Set TextStream = Folder.CreateTe xtFile("Octopus Garden.txt")
' Note that this does not add a line feed to the file.
TextStream.Writ e ("Octopus' Garden ")
TextStream.Writ eLine ("(by Ringo Starr)")
TextStream.Writ eBlankLines (1)
TextStream.Writ eLine ("I'd like to be under the sea in an octopus'
garden in the shade,")
TextStream.Writ eLine ("He'd let us in, knows where we've been -- in his
octopus' garden in the shade.")
TextStream.Writ eBlankLines (2)
TextStream.Clos e
Set TextStream = Folder.CreateTe xtFile("Bathroo mWindow.txt")
TextStream.Writ eLine ("She Came In Through The Bathroom Window (by
Lennon/McCartney)")
TextStream.Writ eLine ("")
TextStream.Writ eLine ("She came in through the bathroom window protected
by a silver spoon")
TextStream.Writ eLine ("But now she sucks her thumb and wanders by the
banks of her own lagoon")
TextStream.Writ eBlankLines (2)
TextStream.Clos e
End Sub
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' GetLyrics
' Purpose:
' Displays the contents of the lyrics files.
' Demonstrates the following
' - FileSystemObjec t.OpenTextFile
' - FileSystemObjec t.GetFile
' - TextStream.Read All
' - TextStream.Clos e
' - File.OpenAsText Stream
' - TextStream.AtEn dOfStream
' - TextStream.Read Line
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
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.OpenTextFil e(TestFilePath &
"\Beatles\Octop usGarden.txt", OpenFileForRead ing)
s = TextStream.read All & NewLine & NewLine
TextStream.Clos e
Set File = fso.GetFile(Tes tFilePath & "\Beatles\Bathr oomWindow.txt")
Set TextStream = File.OpenAsText Stream(OpenFile ForReading)
Do While Not TextStream.AtEn dOfStream
s = s & TextStream.Read Line & NewLine
Loop
TextStream.Clos e
GetLyrics = s
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
' BuildTestDirect ory
' Purpose:
' Builds a directory hierarchy to demonstrate the FileSystemObjec t.
' 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
' - FileSystemObjec t.DriveExists
' - FileSystemObjec t.FolderExists
' - FileSystemObjec t.CreateFolder
' - FileSystemObjec t.CreateTextFil e
' - Folders.Add
' - Folder.CreateTe xtFile
' - TextStream.Writ eLine
' - TextStream.Clos e
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
Function BuildTestDirect ory(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
BuildTestDirect ory = False
Exit Function
End If
If fso.FolderExist s(TestFilePath) Then
BuildTestDirect ory = False
Exit Function
End If
Set TestFolder = fso.CreateFolde r(TestFilePath)
Set TextStream = fso.CreateTextF ile(TestFilePat h & "\ReadMe.tx t")
TextStream.Writ eLine ("My song lyrics collection")
TextStream.Clos e
Set SubFolders = TestFolder.SubF olders
Set SubFolder = SubFolders.Add( "Beatles")
CreateLyrics SubFolder
BuildTestDirect ory = 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("S cripting.FileSy stemObject")
If Not BuildTestDirect ory(fso) Then
MsgBox "Test directory already exists or cannot be created. Cannot
continue."
Exit Sub
End If
MsgBox GenerateDriveIn formation(fso) & NewLine & NewLine
MsgBox GenerateTestInf ormation(fso) & NewLine & NewLine
MsgBox GetLyrics(fso) & NewLine & NewLine
DeleteTestDirec tory fso
End Sub
<
www.clearpointsystems.com