I always use the following function for this. You could use it as is
or just pull out the bits useful for your app.
Regards,
Andrew
' Written by: Office Developer Edition Code Librarian
' Revised by:
' Purpose: Takes a file path and returns either the path, file,
drive or
' file extension portion depending on which constant was
passed in
' Dependencies:
' Comments:
' Error constants
Public Const ERR_SUBSCRIPT As Long = 9
' Enumeration constants
Public Enum opgParsePath
FILE_ONLY
PATH_ONLY
DRIVE_ONLY
FILEEXT_ONLY
End Enum
Public Function ParsePath(strPath As String, lngPart As opgParsePath)
As String
Dim lngPos As Long
Dim strPart As String
Dim blnIncludesFile As Boolean
' Check that this is a file path. Find the last path separator.
lngPos = InStrRev(strPath, "\")
' Determine whether portion of string after last backslash contains
a period
blnIncludesFile = InStrRev(strPath, ".") > lngPos
If lngPos > 0 Then
Select Case lngPart
' Return file name.
Case opgParsePath.FILE_ONLY
If blnIncludesFile Then
strPart = Right$(strPath, Len(strPath) - lngPos)
Else
strPart = ""
End If
' Return path.
Case opgParsePath.PATH_ONLY
If blnIncludesFile Then
strPart = Left$(strPath, lngPos)
Else
strPart = strPath
End If
' Return drive.
Case opgParsePath.DRIVE_ONLY
strPart = Left$(strPath, 3)
' Return file extension.
Case opgParsePath.FILEEXT_ONLY
If blnIncludesFile Then
' Take three characters after period.
strPart = Mid(strPath, InStrRev(strPath, ".") + 1,
3)
Else
strPart = ""
End If
Case Else
strPart = ""
End Select
End If
ParsePath = strPart
ParsePath_End:
Exit Function
End Function
"Paul" <12**************@btinternet.com> wrote in message news:<bj**********@hercules.btinternet.com>...
When I assign Command to FileName I get, for example, "C:\Program
Files\MyApp\FileToDrop.txt"
I already know how to remove the quotation marks from the string but is
there any way of splitting the path and the filename and assigning them to a
different string?
e.g
FileName = "FileToDrop.txt"
Path = "C:\Program Files\MyApp\"
Thanks
Paul
"Norm Cook" <no******@cableone.net> wrote in message
news:vl************@corp.supernews.com... See Command function in help. When you drop a file on your app's icon,
your app will start & Command will hold the filename. So in the form's load
event, you can
FileName = Command
'do whatever
"Paul" <12**************@btinternet.com> wrote in message
news:bj**********@sparta.btinternet.com... Hi,
Does anyone know how I would be able to drag a single file onto my
applications icon and have it run some predefined code.
What I want is to drop an .mp3 file onto my applications icon (not the apps form) and perform the necessary actions then give a confirmation when these actions are done then quit.
Any ideas?
Cheers,
Paul