Reading network pathname (solved)

Reading network pathname (solved)

Postby driessen » Thu Jan 16, 2020 12:00 pm

Hello,

How can I read a full pathname of a network connection?

Example : the drive letter is F:. How do can I get the fulle pathname of the network connection ? (ex. \\COMPUTER1\MAP1\MAP2)

Thanks a lot in advance for any help.
Last edited by driessen on Thu Jan 16, 2020 11:34 pm, edited 1 time in total.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Postby Antonio Linares » Thu Jan 16, 2020 12:18 pm

Dear Michael,

You may use WNetGetUniversalName() or adapt this code to Harbour:

Code: Select all  Expand view  RUN
Sub abc()
Dim fs As Object
Set fs = CreateObject("Scripting.fileSystemObject")
For Each dr In fs.Drives
msgbox dr.DriveLetter & " - " & dr.ShareName
Next
End Sub
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Reading network pathname

Postby driessen » Thu Jan 16, 2020 12:45 pm

Thanks a lot, Antonio.

Unfortunately, I got an "unknown" external on WNetGetUniversalName.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Postby Antonio Linares » Thu Jan 16, 2020 12:50 pm

Michael,

Please try these ones:

Code: Select all  Expand view  RUN
function GetDriveLetter( cPath )

   local o := CreateObject( "Scripting.fileSystemObject" )
   
return o:GetDrive( o:GetDriveName( o:GetAbsolutePathName( cPath ) ) )

function GetAName( cDriveSpec )

   local o := CreateObject( "Scripting.fileSystemObject" )
   
return o:GetDriveName( cDriveSpec )
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Reading network pathname

Postby driessen » Thu Jan 16, 2020 1:17 pm

Sorry, Antonio,

It doesn't work.

I tried this :
Code: Select all  Expand view  RUN
MsgInfo( GetAName( "O" ) )
MsgInfo( GetDriveLetter( "\\COMPUTER3\C\SOFTWARE\JUDA\DATA" ) )
 
The first results in nothing, the seconds returns "object".

I want to know if 2 folders are the same : "O:\JUDA\DATA" and "\\COMPUTER3\C\SOFTWARE\JUDA\DATA".

There is a networkconnection from "\\COMPUTER3\C" to "O:"
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Postby Antonio Linares » Thu Jan 16, 2020 1:19 pm

have you tried like this ?

MsgInfo(GetAName("O:"))
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Reading network pathname

Postby driessen » Thu Jan 16, 2020 1:51 pm

It just returns : "O:"
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Postby nageswaragunupudi » Thu Jan 16, 2020 9:03 pm

Can you please try this function?

Code: Select all  Expand view  RUN
function UNCNAME( cPath )

   local cDrive, cMap

   cPath    := TrueName( cPath )
   if SubStr( cPath, 2, 1 ) == ":"
      cDrive   := Left( cPath, 2 )
      if Empty( cMap := DRIVEMAP( cDrive ) )
         if File( cPath ) .or. IsDir( cPath )
            cPath := "\\" + NetName() + "\" + cPath
            cPath := StrTran( cPath, "
:", "\"  )
         endif
      else
         cPath := cMap + SubStr( cPath, 3 )
      endif
   endif

return cPath

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>

HB_FUNC( DRIVEMAP )
{
   LPCSTR drive = hb_parc( 1 );
   char path[ 80 ];
   DWORD len = 80;

   if ( WNetGetConnection( drive, path, &len ) == 0 ) { hb_retc( path ); }
   else { hb_retc( "
" ); }
}

#pragma ENDDUMP


Usage:
Code: Select all  Expand view  RUN

? UNCNAME( <your_file_or_folder_name> )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10659
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Reading network pathname

Postby driessen » Thu Jan 16, 2020 11:34 pm

Mr. Rao,

Thank you very much. Your solution is working just fine.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Postby nageswaragunupudi » Fri Jan 17, 2020 1:52 pm

Antonio Linares wrote:Dear Michael,

You may use WNetGetUniversalName()


This function is based on the above suggestion:

Code: Select all  Expand view  RUN
HB_FUNC( UNC_NAME )
{
   DWORD cbBuff = 1000;
   TCHAR szBuff[1000];
   UNIVERSAL_NAME_INFO * puni = (UNIVERSAL_NAME_INFO *) &szBuff;
   DWORD dwRes;
   LPCSTR strPath = hb_parc( 1 );

   dwRes = WNetGetUniversalName( strPath, UNIVERSAL_NAME_INFO_LEVEL, puni, &cbBuff );

   if ( dwRes == NO_ERROR ) { hb_retc( puni->lpUniversalName ); }
   else  { hb_retc( strPath ); }
}
 


Please test
Code: Select all  Expand view  RUN

? UNC_NAME( <file_folder_name> )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10659
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Reading network pathname (solved)

Postby Rick Lipkin » Fri Jan 17, 2020 7:28 pm

This code has served me well over the years ..

Code: Select all  Expand view  RUN

// where .exe started from is default directory //

cFILE  := GetModuleFileName( GetInstance() )
nSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,nSTART-1)

msginfo( cDefa )



Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Reading network pathname (solved)

Postby cnavarro » Fri Jan 17, 2020 11:12 pm

Dear Rick, This is not the same?
Code: Select all  Expand view  RUN

? cFilePath( hb_argv( 0 ) )
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Reading network pathname (solved)

Postby nageswaragunupudi » Sat Jan 18, 2020 2:32 am

Rick Lipkin wrote:This code has served me well over the years ..

Code: Select all  Expand view  RUN

// where .exe started from is default directory //

cFILE  := GetModuleFileName( GetInstance() )
nSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,nSTART-1)

msginfo( cDefa )



Rick Lipkin


Mr. Rick

Simpler ways of doing:
Code: Select all  Expand view  RUN

cFilePath( hb_argv( 0 ) )  // Christobal
// OR
cFilePath( ExeName() )
 


But what Mr. driessen asked is totally different. He wanted to convert the file/path name to UNC.

For example, in my case:
Code: Select all  Expand view  RUN

? UNCNAME( "L:\FWH\whatsnew.txt" ) // --> "\\GNRDELL\C\FWH\whatsnew.txt"
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10659
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Reading network pathname (solved)

Postby nageswaragunupudi » Tue Feb 04, 2020 2:24 am

Sorry, we were wasting our time re-inventing the wheel.

FWH already has a function
cFileUNC( cLocalName ) --> cUncPath
from FWH 1805
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10659
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 54 guests