Results 1 to 3 of 3

What reference do i need to add for System.IO.FileInfo

This is a discussion on What reference do i need to add for System.IO.FileInfo within the Excel Questions forums, part of the Question Forums category; Found a snippet of code in VB (not VBA ) that does just what i need. But, i think i ...

  1. #1
    Board Regular
    Join Date
    Mar 2011
    Posts
    90

    Default What reference do i need to add for System.IO.FileInfo

    Found a snippet of code in VB (not VBA) that does just what i need. But, i think i need a reference for these types to work. Do you know what reference i need to add (using VBA project, Excel 2010)? (OR, if i have to browse, to what DLL). In the dialog, the only one that looked like a 'maybe' was one that just said "system" but that does not do it. Thanks if you know the answer to this. Here is the code by the way.
    Thanks,
    tom


    Sub test_path()
    Dim testFile As System.IO.FileInfo
    testFile = My.Computer.FileSystem.GetFileInfo("C:\TestFolder1\test1.txt")
    Dim folderPath As String = testFile.DirectoryName
    MsgBox (folderPath)
    Dim fileName As String = testFile.Name
    MsgBox (fileName)
    End Sub

  2. #2
    Board Regular
    Join Date
    Apr 2010
    Posts
    186

    Default Re: What reference do i need to add for System.IO.FileInfo

    If all you're trying do is take the full path to a file and parse out the folder path and filename, you can just step through the full path backwards looking for the first "\" and set two string vars based on left() and right()

    Code:
    fullPath = "C:\mypath\foo.txt"
    for i = len(fullPath) to 1 step -1
      if mid(fullpath,i,1) = "\" then
        folderPath = left(fullPath,i)
        fileName = right(fullPath,len(fullPath)-i)
        exit for
      end if
    next i

  3. #3
    Board Regular
    Join Date
    Mar 2011
    Posts
    90

    Default Re: What reference do i need to add for System.IO.FileInfo

    Thanks for the example. That will indeed do what i am looking to do at the moment. However, i still wonder about this question, as perhaps i will have a more complex need to reference System.IO. (I must say, i find it a little aggravating when an "official" example is posted (by Microsoft) and they leave out a key piece of information...can't paste the code and have it work, unless you reference something, but they do not tell you what!)

    Anyway, thanks much for the reply, but if anybody knows what box to check in the Tools...References dialog, i'd still appreciate to hear that, too.

    Thanks,
    tom

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com