Results 1 to 19 of 19

Thread: CD Rom

  1. #1
    Guest
    How can I determine the current directory of a CD Rom drive. From a vb generated exe file called from the autorun.inf file. I want to assign the current CD Rom drive to hyperlink field codes in a word document.

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Posts
    29

    Lightbulb

    Have you tried using the VBScripting object? Add a reference in your Project to "Microsoft Scripting Runtime".

    Try using this Code:
    Dim FileSys As FileSystemObject
    Dim iDrive As Drive

    'Open a New Instance of the File System Object
    Set FileSys = New FileSystemObject

    'Iterate through the Dives in the File System
    For Each iDrive In FileSys.Drives
    If (iDrive.DriveType = CDRom) Then
    'Do what you want here
    End If
    Next

  3. #3
    Guest

    Question where am I

    If I run through the file system and get the cd-rom drives how can i determine which cd-rom drive I am currently in. I don't have a problem listing drives just a problem determining which cd-rom drive I am presently in when the CD is inserted. All this to hopefully parse all the http references in about 2500 links to the current drive letter. I want to establish current drive then parse the field codes in the hyperlinks in word to the current drive letter. Thanks for your help!

  4. #4
    Junior Member
    Join Date
    Oct 2000
    Posts
    29

    Lightbulb

    In that case, store a File on the CDRom you know the name of (i.e. Setup.inf or something) and look for something within the File that you recognize (some type of Parameter or something just in case there are 2 CD-ROM Drives and they both have CDs in them and they both have a Setup.inf File, heh).

    That way, you can do the FileSystem procedure above, once you find the Drive Letter, you can either keep using the FileSystem Object to look through the Files, or the VB intrinsic "Dir" command to look for that File.

    Whew!

    If anyone knows a better way, I would like to know.

    Actually, now that I think of it, why not just use App.Path? Hehe.

  5. #5
    Guest

    App Path

    Actually that is what I have just been doing I'm working with ActiveDocument.Path right now it does give me the active directory if I can set that to a variable and cut the http: reference out of the field codes I might just get this. Thanks. Any further suggestions would sure be appreciated.

  6. #6
    Junior Member
    Join Date
    Oct 2000
    Posts
    29
    What type of Project is this? DLL, EXE?

  7. #7
    Guest

    Exe or DLL

    I started this in VBA rather than VB. I opened a doc file by way of a vb exe file and was trying to use the API to get the current directory of the CD by using GetCurrentDirectory. No luck so far on that approach so I tried your suggestion and employed ActiveDocument.Path in VBA which will give me the current directory, all I need now is to parse the http: out of roughly 2500 links built in to company manuals and insert the current directory, so that I don't have to rewrite 2500 links in word.docs. If I can accomplish this in an exe or dll file please get me started as vb is new to me. Thanks appreciate any comments!

  8. #8
    Junior Member
    Join Date
    Oct 2000
    Posts
    29
    Ok, now I don't understand. Are you opening a WordDoc that has HyperLinks in it? Or, when you try to get the App.Path, it's returning "\\[ComputerName]\CurrentDir\CurrentFolder\"?

    I'm not understanding where this http:// is coming from. In VB, when you just type "App.Path", it gives you the Current Path "C:\My Documents\Worddoc1.doc". This way, you just need to Look at the First 3 Characters to get the Drive Letter your in.

    Are you running this through the MS Word VBA or an actual VB.exe? Maybe send me an Email of what you are trying to accomplish, this will help me to better understand. I'm just not sure where you are getting all these Hyperlinks from and what you want to accomplish with them.

    [email protected]

  9. #9
    Guest

    hyperlinks

    in the word file I have all my hyperlinks referenced as http://etc. I just wanted to find the current directory and cut out the http://etc. reference and replace it with the current directory.

  10. #10
    Junior Member
    Join Date
    Oct 2000
    Posts
    29
    So what your saying is that the Hyperlinks are not Websites, but Files on the CDRom? Can you show me a couple of Examples of what the Hyperlinks look like?

  11. #11
    Guest

    Smile hyperlinks

    In word http://127.0.0.1/wcontent/manuals/ha...10cost/toc.doc as I said I originally tried to accomplish this from the API without success all I need to do now is the parse the http:// reference and insert the current directory into the hyperlink field codes. thanks

  12. #12
    Junior Member
    Join Date
    Oct 2000
    Posts
    29
    So in the example: http://127.0.0.1/wcontent/manuals/ha...10cost/toc.doc, the "127.0.0.1" = the CDRom Drive Letter? And if so, then what follows it is the Path to the Files, am I right?

  13. #13
    Guest

    Substitution

    Yeah that is right in that way I don't need to create a file structure and change all the links just to put it on CD and have it navigate as intended. Thanks.

  14. #14
    Junior Member
    Join Date
    Oct 2000
    Posts
    29

    Talking

    You should be able to Copy and Paste this Code into whatever your using, it should be VBA friendly if you are using MS Word.

    Just pass it the HyperLink as a String. For instance, if you have a String Variable that is the Path of a Document you want to Ope, you pass it the Hyperlink like this:

    Dim strFileDoc as String
    strFileDoc = GetPath(MyHyperlink)

    If (Dir(strFileDoc) <> "") then
    'Open the Document
    Else
    'Path does not Exist
    End If



    Private Function GetPath(Byval strHyperLink as String) as String
    Dim i As Integer, j As Integer
    Dim strHyperLink As String
    Dim strPath As String

    'In this Example, the strHyperlink = "http://127.0.0.1/wcontent/manuals/handbook/10cost/toc.doc"
    For i = 1 To 3 'Count to 3 to get to the Path
    j = InStr(j + 1, strHyperLink, "/")
    '1.) 1st time through, j = 6
    '2.) 2nd time through, j = 7
    '3.) 3rd time through, j = 17
    'So now we know that the 17th Position, begins the Path to the Document
    Next i

    'Get the Drive Letter of the CDRom
    strPath = Left$(App.Path, 3) 'D:\

    'Now we need to change all the Forward Slashes
    'to Back Slashes
    Do
    i = InStr(j + 1, strHyperLink, "/")
    If (Not i = 0) Then
    strPath = strPath & Mid$(strHyperLink, j + 1, (i - 1) - j) & "\"
    j = i
    Else
    If (Not Len(Mid$(strHyperLink, j + 1)) = 0) Then
    strPath = strPath & Mid$(strHyperLink, j + 1)
    End If
    End If
    Loop Until i = 0

    'Our End Result is the Path on the CDRom to the Document
    'strPath should = "D:\wcontent\manuals\handbook\10cost\toc.doc"
    GetPath = strPath
    End Function

  15. #15
    Junior Member
    Join Date
    Oct 2000
    Posts
    29
    Get rid of the Variable in the "GetPath" Routine "strHyperLink as String". It is not neccessary.

  16. #16
    Guest

    Talking Thanks

    Thanks, I need to sit down with this and spend some time and right now my website needs some attention.

  17. #17
    Guest

    Success

    mikassa7557 Thanks, with slight alteration the code that you posted just provided me with a working function to insert in normal.dot to parse these files, thanks a million.

  18. #18
    Guest

    Final Code

    I guess I really should throw the final code out here for everyone to see.
    Private Sub CommandButton5_Click()
    Dim i As Integer, j As Integer
    Dim strPath As String
    Dim hLink As Hyperlink
    Set myRange = ActiveDocument.Range(Start:=ActiveDocument.Content.End - 1)

    Count = 0
    For Each hLink In ActiveDocument.Hyperlinks
    Count = Count + 1
    j = 0
    strPath = ActiveDocument.Path & Application.PathSeparator
    For i = 1 To 3
    j = InStr(j + 1, hLink.Address, "/")
    Next i
    Do
    i = InStr(j + 1, hLink.Address, "/")
    If (Not i = 0) Then
    strPath = strPath & Mid$(hLink.Address, j + 1, (i - 1) - j) & "\"
    j = i
    Else
    If (Not Len(Mid$(hLink.Address, j + 1)) = 0) Then
    strPath = strPath & Mid$(hLink.Address, j + 1)
    End If
    End If
    Loop Until i = 0
    Debug.Print strPath
    Next hLink
    End Sub
    Thanks again mikasa7557!!

  19. #19
    Junior Member
    Join Date
    Oct 2000
    Posts
    29

    Talking

    No problem! Glad to help, parsing is fun! I do a lot of EDI files, so I know how sometimes this can be difficult.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width