Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Paths containing spaces

Posted on 1998-12-30
6
Medium Priority
?
289 Views
Last Modified: 2010-05-03
When using the mciSendString with a pathing variable, it doesn't like the spaces in the path.  For example:
MyPath = "c:\Program Files\filename.avi" confuses the command; whereas MyPath = "c:\Program_Files\filename.avi" is okay.  Any way around this?  I cannot alway control the directory name the user creates.
0
Comment
Question by:BWATERS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:obregoru
ID: 1453329
Try """c:\Program Files\filename.avi"""

You need to include quotes in the string, and by placing two quotes together, you tell VB to use a quote as a character and not a delimiter.
0
 

Author Comment

by:BWATERS
ID: 1453330
Thanks for the reply...but NG. Here's what I have:

CmdStr = ("open " & AVIFileName & " Type AVIVideo alias Animation parent " _
           & LTrim$(Str$(frmAVI.hwnd)) + " style " + LTrim$(Str$(WS_CHILD)))

Where AVIFileName = F:\tgsc\KeySpan\RD Project Tracker\search.avi

When I send the CmsStr the mciSendString sees the spaces in the path and expects a parameter.  What can one do?
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1453331
Strip the spaces from the path string. This might cause problems for paths that are supposed to include spaces (i.e. C:\Program Files\Office97).


This function will remove all spaces from a string. Use it to remove spaces from OldPath using the statement.

NewPath = NoSpace(OldPath)

Private Function NoSpace(ByVal PathString) As String
Dim i As Integer
Dim FirstPart As String
Dim SecondPart As String

   PathString = Trim$(PathString) ' get rid of leading/trailing spaces

Do
   i = InStr(PathString, " ")  ' find the first space
   If i = 0 Then Exit Do ' no more spaces found
   FirstPart = Left$(PathString, i - 1)
   SecondPart = Right$(PathString, Len(PathString) - i)
   PathString = FirstPart & SecondPart
Loop
NoSpace = PathString
End Function



This second function only removes those spaces that are next to the backslash characters, and leaves all the others in place. A similar method could eliminate spaces next to the colon, or the period characters.

Private Function NoSpace(ByVal PathString) As String
Dim i As Integer
Dim FirstPart As String
Dim SecondPart As String

   PathString = Trim$(PathString) ' get rid of leading/trailing spaces

Do
   i = InStr(PathString, " \")  ' space before slash
   If i = 0 Then Exit Do ' no more spaces found
   FirstPart = Left$(PathString, i - 1)
   SecondPart = Right$(PathString, Len(PathString) - i)
   PathString = FirstPart & SecondPart
Loop

Do
   i = InStr(PathString, "\ ")  ' space after slash
   If i = 0 Then Exit Do ' no more spaces found
   FirstPart = Left$(PathString, i)
   SecondPart = Right$(PathString, Len(PathString) - i - 1)
   PathString = FirstPart & SecondPart
Loop
NoSpace = PathString
End Function


Finally, this function will replace any spaces in the path with the underscore character:


Private Function NoSpace(ByVal PathString) As String
Dim i As Integer
Dim char As String

   PathString = Trim$(PathString) ' get rid of leading/trailing spaces

For i = 1 to Len(PathString)
   char = Mid$(PathString, i, 1)
   If char = " " Then Mid$(PathString, i, 1) = "_"
Next i

NoSpace = PathString
End Function
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1453332
hddp666: his sample include "program files" so why answer this question.
BWATERS:
Use the short filename of the file. Here is a sample of how to convert the long filename to a short filename

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Sub Command1_Click()
    Dim str As String
    str = String$(260, 0)
    Call GetShortPathName("c:\my documents\uitnodiging.ppt", str, 255)
    MsgBox str
End Sub

0
 

Author Comment

by:BWATERS
ID: 1453333
Thanks Mirkwood
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 400 total points
ID: 1453334
Thankx

Use the short filename of the file. Here is a sample of how to convert the long filename to a short filename

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Sub Command1_Click()
    Dim str As String
    str = String$(260, 0)
    Call GetShortPathName("c:\my documents\uitnodiging.ppt", str, 255)
    MsgBox str
End Sub

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question