Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Getting directory? VB 9.


  • Please log in to reply
14 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 01:00 PM

Hi, how would i get the directory for a file, data.txt for example, i know how to use System.IO for things like creating/writing files, deleting files and moving files. Would it be along theese lines, all ones through google i do not understand, espesially ones from MSDN (I swere they make it as comlicated as possible :thumbsup: ) so any help would be brilliant, i would proboly then make a program with this knowlage that searches your computer for the specified ile or folder, this way i could practaise two things, searching and obtaining a directory and also adding things to a list of results so you oculd then choose the right file if more than one have been found with the same name but in different directorys.

Thanks in advance,

Oliver.

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:46 AM

Posted 14 December 2008 - 01:45 PM

I'm confused... are you searching for for a file, or are you looking to split the file and path given the fully qualified name?

If it's the second one, you'd need to use this: http://msdn.microsoft.com/en-us/library/sy...th_members.aspx

If it's the first one, you'd need to write that yourself as the Framework does not have that built in :thumbsup:

BillyIII
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 02:05 PM

Well, say i had two text boxes and a button, one text box is input, the file or executable name, and the second box is the output, the directory. When you click the button it gets the directory of the file name in input and writes the directory in the output. So if i put "mbam.exe" then clicked it would put in output "C:\Program Files\Malwarebytes' Anti-Malware\mbam.exe". So you say this function is not in the framework? Then how would this be acheved? Or can it?

#4 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 02:09 PM

The Full path method bit sounds promasing but i dont have a clue how that works =S

#5 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:46 AM

Posted 14 December 2008 - 02:23 PM

You need to search for the file. There's no built in function for that. That EXE file could be anywhere.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#6 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 02:34 PM

I see. how would i search for it though? This is what i am trying to acheve so i just went round in a circle :thumbsup:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		PathO.Text = Path.GetFullPath(PathI.Text)
	End Sub

I just used that but it dosnt appere to do anything?

#7 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 02:39 PM

"\FLUMP\Data\udata.txt" Returns "C:\FLUMP\Data\udata.txt" :S it is only addin C: onto it?

#8 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:46 AM

Posted 14 December 2008 - 03:27 PM

GetFullPAth does not find anything. It just takes a path and turns it into a fully qualified one.

For example, if your exe is on your desktop, then GetFullPath("./SomeExE.EXE") returns something to the effect of C:\Users\Billy\Desktop\SomeExE.EXE.

To find an arbitrary EXE you need to write the search function yourself.

Billy3

Edited by Billy O'Neal, 14 December 2008 - 03:27 PM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#9 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:46 AM

Posted 14 December 2008 - 03:30 PM

Have you ever written an recursive function? I.e., one that calls itself?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#10 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 03:36 PM

What do you mean? So that sort of shows, no io have not.

Edited by Wolfy87, 14 December 2008 - 03:36 PM.


#11 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:07:46 AM

Posted 14 December 2008 - 03:40 PM

Perhaps the ShowOpen function is what you are looking for? Every higher level language that I know of has a default File chooser type function, and even those not so high level (like Perl, for example).

#12 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 14 December 2008 - 03:43 PM

From what i can tell this looks as though it displays printing dialogs etc but i wish to find the directory of a file or folder when the name of it is specified.

#13 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:46 AM

Posted 14 December 2008 - 04:29 PM

Try to write something like this (What I'm writing is pseudocode:

Function find(ByVal dir as string, ByVal searchFor as string) as string
Private retVar as string
for each directory as string in My.Computer.FileSystem.GetDirectories(dir)
retVar += find(directory, searchFor) 'Note that this function calls itself...
next
for each file as string in my.computer.filesystem.GetFiles(dir)
if file.EndsWith(searchFor)
retVar += file + Environment.Newline
endif
next
return retVar
end function

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#14 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:46 PM

Posted 19 December 2008 - 08:51 AM

How do they call themselfs, i dont understand?

#15 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:06:46 AM

Posted 20 December 2008 - 11:05 AM

Function find(ByVal dir as string, ByVal searchFor as string) as string
Private retVar as string
for each directory as string in My.Computer.FileSystem.GetDirectories(dir)
retVar += find(directory, searchFor) 'Note that this function calls itself...
next
for each file as string in my.computer.filesystem.GetFiles(dir)
if file.EndsWith(searchFor)
retVar += file + Environment.Newline
endif
next
return retVar
end function
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users