rdir returns unwanted directories

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

rdir returns unwanted directories

bill-lancaster
This line of code returns files AND directories

sFileArray = RDir(sPathThumbs, "*", gb.File)

Any ideas would be welcome

Gambas 3.9.2
Kubuntu 16.10
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Gianluigi
You mean this?

sFileArray = RDir(sPathThumbs, "*.{png,jpg}", gb.File)

Regards
Gianluigi

2017-05-28 12:00 GMT+02:00 bill-lancaster <[hidden email]>:

> This line of code returns files AND directories
>
> sFileArray = RDir(sPathThumbs, "*", gb.File)
>
> Any ideas would be welcome
>
> Gambas 3.9.2
> Kubuntu 16.10
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.
> com/rdir-returns-unwanted-directories-tp59204.html
> Sent from the gambas-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Gianluigi
In reply to this post by bill-lancaster
If you do not want to search in the sub directories use Dir

Regards
Gianluigi

2017-05-28 12:00 GMT+02:00 bill-lancaster <[hidden email]>:

> This line of code returns files AND directories
>
> sFileArray = RDir(sPathThumbs, "*", gb.File)
>
> Any ideas would be welcome
>
> Gambas 3.9.2
> Kubuntu 16.10
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.
> com/rdir-returns-unwanted-directories-tp59204.html
> Sent from the gambas-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

bill-lancaster
In reply to this post by Gianluigi
By specifying only files of type png or jpg directories would be  excluded any way.
So this would produce the same result:-
sFileArray = RDir(sPathThumbs, "*.{png,jpg}")

Any way, I must thank you because I'd been looking for a way to specify multiple file types and you've answered my question!

Bill
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Charlie
I presume you just want the file name not the folder details. If so try this, sFiles will contain just the file name: -

Public Sub Form_Open()
Dim sFileArray As New String[]
Dim sFiles As New String[]
Dim sTemp As String

sFileArray = RDir(User.Home, "*", gb.File)

For Each sTemp In sFileArray
sFiles.Add(Mid(sTemp, RInStr(sTemp, "/") + 1))
Next

End

Check out www.gambas.one

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

bill-lancaster
Thank you Charlie,
In fact I'm looking for all the image files in the sPathThumbs folder
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Gianluigi
In reply to this post by Charlie
now I understand the question :-)

Regards
Gianluigi

2017-05-28 15:05 GMT+02:00 Charlie <[hidden email]>:

> I presume you just want the file name not the folder details. If so try
> this,
> sFiles will contain just the file name: -
> *Public Sub Form_Open()
> Dim sFileArray As New String[]
> Dim sFiles As New String[]
> Dim sTemp As String
> sFileArray = RDir(User.Home, "*", gb.File)
> For Each sTemp In sFileArray
>   sFiles.Add(Mid(sTemp, RInStr(sTemp, "/") + 1))
> Next
> End*
>
>
>
> -----
> Check out www.gambas.one
> --
> View this message in context: http://gambas.8142.n7.nabble.
> com/rdir-returns-unwanted-directories-tp59204p59208.html
> Sent from the gambas-user mailing list archive at Nabble.com.
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Tobias Boege-2
In reply to this post by Charlie
On Sun, 28 May 2017, Charlie wrote:

> I presume you just want the file name not the folder details. If so try this,
> sFiles will contain just the file name: -
> *Public Sub Form_Open()
> Dim sFileArray As New String[]
> Dim sFiles As New String[]
> Dim sTemp As String
> sFileArray = RDir(User.Home, "*", gb.File)
> For Each sTemp In sFileArray
>   sFiles.Add(Mid(sTemp, RInStr(sTemp, "/") + 1))
> Next
> End*

Instead of Mid(sTemp, RInStr(sTemp, "/") + 1) you may want to use the
appropriately named function File.Name(sTemp).

Still, using RDir(..., "*", gb.File) only gives me files, no directories,
so I can't reproduce your original problem here.

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Gianluigi
Hi Tobias,
if I have in my home a directory named image with a subfolder named
my-image, containing both images, and I write:

Public Sub Main()

  Dim sFileArray As String[]
  Dim s As String
  Dim sPath As String = "~/image"
  ' Run directory e sub-directory
  sFileArray = RDir(sPath, "*.{png,jpg}", gb.File)
  For Each s In sFileArray
    Print s
  Next

End

I obtain this:

my-image/actress.png
my-image/alfa.jpg
my-image/lamb.jpg
snail.jpg
horse.jpg
oggy.png
sparkle.png
homer.jpg


In the first three cases, to get the only file name, I need your suggestion.

Do not work so RDir to you?

Regards
Gianluigi

2017-05-28 17:40 GMT+02:00 Tobias Boege <[hidden email]>:

> On Sun, 28 May 2017, Charlie wrote:
> > I presume you just want the file name not the folder details. If so try
> this,
> > sFiles will contain just the file name: -
> > *Public Sub Form_Open()
> > Dim sFileArray As New String[]
> > Dim sFiles As New String[]
> > Dim sTemp As String
> > sFileArray = RDir(User.Home, "*", gb.File)
> > For Each sTemp In sFileArray
> >   sFiles.Add(Mid(sTemp, RInStr(sTemp, "/") + 1))
> > Next
> > End*
>
> Instead of Mid(sTemp, RInStr(sTemp, "/") + 1) you may want to use the
> appropriately named function File.Name(sTemp).
>
> Still, using RDir(..., "*", gb.File) only gives me files, no directories,
> so I can't reproduce your original problem here.
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Tobias Boege-2
On Sun, 28 May 2017, Gianluigi wrote:

> Hi Tobias,
> if I have in my home a directory named image with a subfolder named
> my-image, containing both images, and I write:
>
> Public Sub Main()
>
>   Dim sFileArray As String[]
>   Dim s As String
>   Dim sPath As String = "~/image"
>   ' Run directory e sub-directory
>   sFileArray = RDir(sPath, "*.{png,jpg}", gb.File)
>   For Each s In sFileArray
>     Print s
>   Next
>
> End
>
> I obtain this:
>
> my-image/actress.png
> my-image/alfa.jpg
> my-image/lamb.jpg
> snail.jpg
> horse.jpg
> oggy.png
> sparkle.png
> homer.jpg
>
>
> In the first three cases, to get the only file name, I need your suggestion.
>
> Do not work so RDir to you?
>

Oh, now the whole thread makes sense to me! I thought your problem was that
if you have a *directory* named "x.jpg" and issued

  RDir(..., "*.{png,jpg}", gb.File)

the gb.File filter was ignored and you were reported the directory "x.jpg",
because the "*.{png,jpg}" pattern matched. But you just wanted to get rid of
the directory component. Then you have your solution (use File.Name on s)
and there is no problem. Our RDir()s behave the same.

Regards,
Tobi

--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Gianluigi
Finally, it's all clear to me as well.
In my example, just change the code like this:

Print File.Name(s)

Thank you Tobias

Regards
Gianluigi

2017-05-28 19:29 GMT+02:00 Tobias Boege <[hidden email]>:

> On Sun, 28 May 2017, Gianluigi wrote:
> > Hi Tobias,
> > if I have in my home a directory named image with a subfolder named
> > my-image, containing both images, and I write:
> >
> > Public Sub Main()
> >
> >   Dim sFileArray As String[]
> >   Dim s As String
> >   Dim sPath As String = "~/image"
> >   ' Run directory e sub-directory
> >   sFileArray = RDir(sPath, "*.{png,jpg}", gb.File)
> >   For Each s In sFileArray
> >     Print s
> >   Next
> >
> > End
> >
> > I obtain this:
> >
> > my-image/actress.png
> > my-image/alfa.jpg
> > my-image/lamb.jpg
> > snail.jpg
> > horse.jpg
> > oggy.png
> > sparkle.png
> > homer.jpg
> >
> >
> > In the first three cases, to get the only file name, I need your
> suggestion.
> >
> > Do not work so RDir to you?
> >
>
> Oh, now the whole thread makes sense to me! I thought your problem was that
> if you have a *directory* named "x.jpg" and issued
>
>   RDir(..., "*.{png,jpg}", gb.File)
>
> the gb.File filter was ignored and you were reported the directory "x.jpg",
> because the "*.{png,jpg}" pattern matched. But you just wanted to get rid
> of
> the directory component. Then you have your solution (use File.Name on s)
> and there is no problem. Our RDir()s behave the same.
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: rdir returns unwanted directories

Charlie
In reply to this post by Tobias Boege-2
Tobias Boege-2 wrote
Instead of Mid(sTemp, RInStr(sTemp, "/") + 1) you may want to use the
appropriately named function File.Name(sTemp).
Thanks Tobi, I didn't know that one.

Check out www.gambas.one

Loading...