14 Replies - 19874 Views - Last Post: 22 December 2011 - 12:21 AM Rate Topic: -----

#1 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 01:01 AM

So im trying to get evything that has ends with .iso into a list box, tryed a couple of things but not getting anywhere as yeat, i will keep trying but could someone please help in the meantime? Thanks

Here is code.

Dim Locate As String = Application.StartupPath & "\Games\"
ListBox1.Items.Add(Locate.EndsWith("*.iso"))


The Locate String is there because thats the location where the iso files are but the application is in the root of the drive.
The ListBox1 command is fairly easy to understand, if you dont i can explain what i was trying to achieve but dont think i need to.

Thank in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Get List Of Specific Files In Specific Folder?

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 02:12 AM

I usually use DirectoryInfo.GetFiles method to get all files in a directory. You can specify search pattern too if you want to, like "*.iso"

There are samples at the bottom:
http://msdn.microsof...y/ms143327.aspx
Was This Post Helpful? 1
  • +
  • -

#3 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 04:20 AM

thankyou very much, it worked a treat, BUT! when the program writes the file names to the listbox its also adding the .iso extension. do you know if this can be removed? i was gonna try TRIM in there somewhere.
Was This Post Helpful? 0
  • +
  • -

#4 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 04:57 AM

I would use Substring method to remove the last 4 characters of a string (the .iso ending).
Was This Post Helpful? 0
  • +
  • -

#5 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 05:22 AM

substring is not working for me atm, its saying that ".iso" is not an integer ... anyways, will try again tomorrow, a fresh brain might help me a bit more. Thanks anyways.
Was This Post Helpful? 0
  • +
  • -

#6 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 07:09 AM

You should always post what you are trying because you are using substring in a wrong way. Substring takes two integers as input: starting position and length.

So the correct way to use it is this:
        Dim file As String = "C:\temp\myiso.iso"
        Const extension As String = ".iso"
        Dim file2 As String = file.Substring(0, file.Length - extension.Length)
        Console.WriteLine(file2)


Was This Post Helpful? 0
  • +
  • -

#7 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Get List Of Specific Files In Specific Folder?

Posted 19 December 2011 - 01:04 PM

There is, I'm pretty sure, a method in My.Computer.FileSystem called GetFileNameWithoutExtension.
However, you'll need to loop through the folders contents.
Was This Post Helpful? 0
  • +
  • -

#8 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: Get List Of Specific Files In Specific Folder?

Posted 20 December 2011 - 10:43 PM

janne_panne <- I have tried some things that you suggested but this is the closest that ive come. is there something wrong with this? I am getting an UnHandled Exception Error.

Details = Length cannot be less than zero.
Parameter name: Length.

Dim ISO As String = "*.iso"
        Dim DirInfo As DirectoryInfo = New DirectoryInfo(Locate)
        Dim Files() As FileInfo = DirInfo.GetFiles(ISO, SearchOption.AllDirectories)
        Dim File As FileInfo

        Const extension As String = ".iso"
        For Each File In Files
            lstTitle.Items.Add(File.Name)
            lstTitle.Text.Substring(0, lstTitle.Text.Length - extension.Length)
            lblCount.Text = lstTitle.Items.Count
        Next (File)


Also, JimmyBo i tried looking for what you suggested but couldn't find it!
Was This Post Helpful? 0
  • +
  • -

#9 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Get List Of Specific Files In Specific Folder?

Posted 20 December 2011 - 11:12 PM

I don't see you setting the value of lstTitle anywhere so the error is that lstTitle has a length of zero and you're subtracting from that.
Was This Post Helpful? 0
  • +
  • -

#10 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: Get List Of Specific Files In Specific Folder?

Posted 20 December 2011 - 11:22 PM

View PostjimmyBo, on 20 December 2011 - 11:12 PM, said:

I don't see you setting the value of lstTitle anywhere so the error is that lstTitle has a length of zero and you're subtracting from that.



Is this what you mean, i just added and changed a little bit of code.

Dim TitleLength As Integer = lstTitle.Text.Length ' I added this to give it an integer length
lstTitle.Text.Substring(TitleLength, lstTitle.Text.Length - extension.Length) ' in the old code there is a 0 and i changed that to TitleLength.


Please explain if this is what you ment.
Was This Post Helpful? 0
  • +
  • -

#11 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Get List Of Specific Files In Specific Folder?

Posted 21 December 2011 - 12:52 AM

What I mean is - the string that you are getting the length of could have a length of 0.
Was This Post Helpful? 0
  • +
  • -

#12 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Get List Of Specific Files In Specific Folder?

Posted 21 December 2011 - 02:57 AM

Try this:

        Const extension As String = ".iso"
        For Each File In Files
            Dim fileName as string = File.Name
            fileName = fileName.Substring(0, fileName.Length - extension.Length)
            lstTitle.Items.Add(fileName)
        Next
        lblCount.Text = lstTitle.Items.Count


Was This Post Helpful? 1
  • +
  • -

#13 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: Get List Of Specific Files In Specific Folder?

Posted 22 December 2011 - 12:15 AM

thanks janne_panne <- worked a treat, i see what i was doing wrong. Thankyou.
Now for the other part!! before i was able to get the picture as in the other post but now its not letting me. i think its because they are classed as file names now, not lstTitle.Text.
Please goto my other post about the picture box and see. Thankyou again!
Was This Post Helpful? 0
  • +
  • -

#14 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Get List Of Specific Files In Specific Folder?

Posted 22 December 2011 - 12:16 AM

Sorry - I don't see the post. Can you link to it?
Was This Post Helpful? 0
  • +
  • -

#15 PNJLj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 09

Re: Get List Of Specific Files In Specific Folder?

Posted 22 December 2011 - 12:21 AM

@JimmyBo

Other Post

Its okay now thoe, its all fixed. Thanks anyways.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1