How to find if a path contains a valid file name

Post

Posted
Rating:
#1 (In Topic #395)
Regular
bill-lancaster is in the usergroup ‘Regular’
I need to know if sVar is just a directory or if it contains a file name
This is best I can do:-

Code

Dim sVar as string
sVar = User.Home &/ "00.mp3"
Print IsDir(File.Dir(sVar) &/ File.Name(sVar))
Is there a better way?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
You can reduce the code to: -

Code (gambas)

  1. Print IsDir(User.Home &/ "00.mp3")
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
Serban is in the usergroup ‘Regular’
That's easy: :)

Code (gambas)

  1. Dim strFilePath As String
  2. '--- It's either you get the path building it in a procedure, OR, just build the string, according to a specific situation
  3. '--- strFilePath= Application.Path & "/App.conf" '--- it's just an example, can be more ellaborate than that.
  4. If Exist(strFilePath) Then
  5.   '--- DoWhatIsRequired()
  6.   '--- BranchForErrors()
The other approach, would be using the Dir(), then IsDir(), but it depends very much on the specifics of the App.

The only thing necessary for the triumph of evil is for good men to do nothing.”― Edmund Burke;
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
Serban is in the usergroup ‘Regular’

bill-lancaster said

I need to know if sVar is just a directory or if it contains a file name

Are you SURE YOU need to know?
Why would you need?
In my view, THE COMPUTER needs to know. Your approach is from the human perspective. It has nothing to do with what the computer needs to know.
Try the sample code I put before this comment.
Also, try to get the computer's perspective, since me, or you, or anyone else as users, we need buttons and labels and the like, while the computer, needs a different type of data: figures. Numbers.

The only thing necessary for the triumph of evil is for good men to do nothing.”― Edmund Burke;
It's easy to die for an idea. It is way harder to LIVE for your idea! (Me)
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
bill-lancaster is in the usergroup ‘Regular’
 Thanks for the replies and thank you cogier, IsDir() does the job.  File.Dir() will truncate the path string if there is no '/' at the end.
Thanks again
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
Cedron is in the usergroup ‘Regular’

.... and carry a big stick!
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
bill-lancaster is in the usergroup ‘Regular’
Thanks Cedron
Online now: No Back to the top
1 guest and 0 members have just viewed this.