MSFN Forum: VB Advanced browse Full path name for file - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

VB Advanced browse Full path name for file Rate Topic: -----

#1 User is offline   mlacaille 

  • Group: Members
  • Posts: 4
  • Joined: 18-October 04

Posted 18 October 2004 - 10:37 PM

I'm trying to write a script that will promt a browse windows and will return the full path (with space) of a file so I can use it in my script to compare another file. Cant get the script to work because there is some spaces in the path name.

HLP Please :wacko:

This is the script that I got from the net but it dose not work with space name ??

Dim ShellApp, Ret, s, i
Set ShellApp = CreateObject("Shell.Application")

On Error Resume Next
Set Ret = ShellApp.BrowseForFolder(0, "Choose file.", 16384)
s = Ret.title
If Err.number <> 0 Then
MsgBox "Cancelled"
WScript.Quit
End If

s = GetPath(Ret, i)
MsgBox s & "-" & cstr(i)
'--show full path and type of item returned. 0-namespace. 1-drive. 2-folder. 3-file.
Set ShellApp = nothing
WScript.Quit

Function GetPath(Fil, iItem)
Dim Pt1, fPar, sn, Obj, sType
On Error Resume Next
sn = Fil.title
Set fPar = Fil.parentfolder

Set Obj = fPar.parsename(sn) '--return item selected as a Shell FolderItem.

If Obj.isfilesystem = false Then
Pt1 = instr(sn, ":")
If Pt1 = 0 Then
iItem = 0 '--namespace.
getpath = sn
Else
iItem = 1 '--drive.
getpath = mid(sn, (Pt1 - 1), 2) & "\"
End If
Set Obj = nothing
exit Function
End If

sType = Obj.type '--Get object Type as shown in folder Details view.

If instr(sType, "Folder") = 0 Then
iItem = 3 '--file.
Else
iItem = 2 '--folder.
End If

getpath = Obj.path
Set Obj = nothing
End Function


#2 User is offline   ardnelias 

  • Newbie
  • Group: Members
  • Posts: 49
  • Joined: 06-December 03

Posted 19 October 2004 - 12:45 AM

Look up this link for somer relevant code...
http://groups.yahoo....py/message/2251
:)

#3 User is offline   mlacaille 

  • Group: Members
  • Posts: 4
  • Joined: 18-October 04

Posted 19 October 2004 - 01:27 PM

Thanks

I looked at the scripts, I hade a similar scripts but it only gives me the path without the filename

#4 User is offline   mlacaille 

  • Group: Members
  • Posts: 4
  • Joined: 18-October 04

Posted 19 October 2004 - 10:06 PM

I Found this script that looks ok but if the file name is spaced it does not work It tried adding value to get it to work but with no succes.

Quote

'-- Hwnd is always 0. Title is browse window caption. RootFolder is optional top folder to show.
'-- Options has several possibilities:
'-- 1 - only allows selection of system folders. (doesn't seem to work.)
'-- 2 - don't show network folders below domain level. (doesn't work on stand-alone system.)
'-- 8 - only allow selection of File System ancestors(??) (on stand-alone system nothing can be selected.)
'--  16 - adds a text input but only valid entries will be returned; cannot create a folder.
'--  4096 - only computers can be selected.
'--  8192 - only a printer can be selected.
'--  16384 - full browsing, includes files.
'--  This script uses the FolderItems object properties to Get path and
'-- find out what type of item it is.

'---------------------------------------------------------

Dim ShellApp, Ret, s, i
Set ShellApp = CreateObject("Shell.Application")

On Error Resume Next
Set Ret = ShellApp.BrowseForFolder(0, "Choose file.", 16384)
s = Ret.title
  If Err.number <> 0 Then
  WScript.Quit
  End If

    s = GetPath(Ret, i)
    MsgBox s & "-" & cstr(i)  '--show full path and type of item returned. 0-namespace. 1-drive. 2-folder. 3-file.
    Set ShellApp = nothing
    WScript.Quit

   
   
Function GetPath(Fil, iItem) 
Dim Pt1, fPar, sn, Obj, sType
    On Error Resume Next
          sn = Fil.title
      Set fPar = Fil.parentfolder
   
      Set Obj = fPar.parsename(sn) '--return item selected as a Shell FolderItem.
     
    '--weed out namespaces and drives. If it's a namespace or drive it can't
    '--return a FolderItem so the last Call caused an error and Obj is therefore
    '--Not part of the filesystem:
   
        If Obj.isfilesystem = false Then
            Pt1 = instr(sn, ":")
          If Pt1 = 0 Then
              iItem = 0  '--namespace.
              getpath = sn
          Else
            iItem = 1 '--drive.
            getpath = mid(sn, (Pt1 - 1), 2) & "\"  '--Get letter before : and add "\" If drive.
          End If 
        Set Obj = nothing 
          exit Function
        End If
       
          '--it's a file or folder. find out which and Get path:
        sType = Obj.type  '--Get object Type as shown in folder Details view.
                        '-- Should be able to use: If Obj.IsFolder = True..... but it doesn't work.
               
      If instr(sType, "Folder") = 0 Then  '--in detail view a folder will be type "File Folder".
            iItem = 3  '--file.
      Else
            iItem = 2  '--folder.
      End If
     
          getpath = Obj.path
      Set Obj = Nothing
    End Function


#5 User is offline   no_siht 

  • Group: Members
  • Posts: 9
  • Joined: 23-July 04

Posted 21 October 2004 - 03:51 AM

why not use a common dialog box???

#6 User is offline   mlacaille 

  • Group: Members
  • Posts: 4
  • Joined: 18-October 04

Posted 21 October 2004 - 03:48 PM

Basically what I’m doing is creating a script that prompt the user for a choice of taking a picture of the computer (with Prism Deploy) or finding the changes on the computer with a previous image file.

I needs to select the previous image file because my scripts writes the script for Prism Deploy depending on the user choice and/or the old image selected.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy