Solved

Paths containing spaces

Posted on 1998-12-30
6
279 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
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now