Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #269

Re: Splitting a string containg filename+path and arguemnts

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Karl E. Peterson <karl@exmvps.org>
Newsgroups microsoft.public.vb.general.discussion, comp.lang.basic.visual.misc
Subject Re: Splitting a string containg filename+path and arguemnts
Date Wed, 15 Jun 2011 11:14:08 -0700
Organization exMVPs.org
Lines 63
Message-ID <itaspj$oik$1@dont-email.me> (permalink)
References <itaab6$n61$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset="iso-8859-1"; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Wed, 15 Jun 2011 18:14:11 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="wsO231DXy8gPg8ZR895Ikw"; logging-data="25172"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qfc/ABcMc/klvyD63nl+/8MD1SCbJR9o="
X-Newsreader MesNews/1.08.03.00-gb
X-Face G"ln~:.wBqHZznO'(lJjjprxGYAjIF7#^u)lx,@"H'F#uXm%j`T6kxat5rq092aW;K*#<!y <6K)wt3HjA)V"XV`W3}Qts*D['Jm:qqpgttEl^wk@9{HJglN-Q'.91Af~ySM>m4jZ(2aW$34N&B&E@ j~tjGV-aC18j1y>zi.\[ZGXsd
Cancel-Lock sha1:62YZ4X38tqjLsb7/WQHTSddolGE=
Xref x330-a1.tempe.blueboxinc.net comp.lang.basic.visual.misc:269

Cross-posted to 2 groups.

Show key headers only | View raw


It happens that Leo formulated :
> I am writing a Shell() replacement that I intend to be a drop in replacement. 
> I am using ShellExecuteEx so I can parse a n image or text file in. The 
> problem comes with spliting the arguements from the path+filename, what is 
> the best way to split them assuming possible paths with spaces that aren't 
> quoted. An example that works with Shell() and WinExec (I know I shouldn't be 
> using it) but I strugle with spliting is C:\Program Files\Windows 
> NT\Accessories\wordpad.exe C:\Users\username\Documents\somertf.rtf . 
> PathRemoveArgs gets confused and cuts the path at the space in "Program 
> Files".

If you have a string that contains an unquoted path with embedded 
spaces *and* arguments, you're fairly hosed.  Where are you getting 
that from?  I think you'll need to attack, or reconsider, the source.

If you just need to split filename and filepath, I use these...

   Private Declare Sub PathStripPathW Lib "shlwapi" (ByVal lpszPath As 
Long)
   Private Declare Function PathRemoveBackslashW Lib "shlwapi" (ByVal 
lpszPath As Long) As Long


   Public Function PathStripFile(ByVal Path As String) As String
      Dim FileName As String
      ' Removes the path portion of a fully qualified path and file.
      FileName = PathStripPath(Path)
      ' Remove filename from original path.
      If Len(FileName) < Len(Path) Then
         Path = Left$(Path, Len(Path) - Len(FileName))
      Else
         Path = ""
      End If
      ' Take off trailing backslash for consistency.
      PathStripFile = PathRemoveBackslash(Path)
   End Function

   Public Function PathStripPath(ByVal Path As String) As String
      Dim Buffer As String
      ' Removes the path portion of a fully qualified path and file.
      Buffer = String$(MAX_PATH, 0)
      Mid$(Buffer, 1) = Path
      Call PathStripPathW(StrPtr(Buffer))
      PathStripPath = TrimNull(Buffer)
   End Function

   Public Function PathRemoveBackslash(ByVal Path As String) As String
      Dim Buffer As String
      ' Removes the trailing backslash from a given path.
      Buffer = String$(MAX_PATH, 0)
      Mid$(Buffer, 1) = Path
      Call PathRemoveBackslashW(StrPtr(Buffer))
      ' Results point to position within buffer of null terminator,
      ' or to the last character if there was no backslash, so it's
      ' almost insane to do the math. Far easier to TrimNull!
      PathRemoveBackslash = TrimNull(Buffer)
   End Function

-- 
.NET: It's About Trust!
http://vfred.mvps.org

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Find similar


Thread

Splitting a string containg filename+path and arguemnts Leo <ttdhead@gmail.com> - 2011-06-15 22:59 +1000
  Re: Splitting a string containg filename+path and arguemnts Deanna Earley <dee.earley@icode.co.uk> - 2011-06-15 15:21 +0100
  Re: Splitting a string containg filename+path and arguemnts Karl E. Peterson <karl@exmvps.org> - 2011-06-15 11:14 -0700

csiph-web