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

TomCon

Active Member
Joined
Mar 31, 2011
Messages
385
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top