?
Solved

Paths containing spaces

Posted on 1998-12-30
6
Medium Priority
?
287 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
Independent Software Vendors: 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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