FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Reading network pathname (solved)
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Reading network pathname (solved)
Posted: 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.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Reading network pathname
Posted: Thu Jan 16, 2020 12:18 PM
Dear Michael,

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

Code (fw): Select all Collapse
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
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Reading network pathname
Posted: 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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Reading network pathname
Posted: Thu Jan 16, 2020 12:50 PM
Michael,

Please try these ones:

Code (fw): Select all Collapse
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
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Reading network pathname
Posted: Thu Jan 16, 2020 01:17 PM
Sorry, Antonio,

It doesn't work.

I tried this :
Code (fw): Select all Collapse
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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Reading network pathname
Posted: Thu Jan 16, 2020 01:19 PM

have you tried like this ?

MsgInfo(GetAName("O:"))

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Reading network pathname
Posted: Thu Jan 16, 2020 01:51 PM

It just returns : "O:"

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Reading network pathname
Posted: Thu Jan 16, 2020 09:03 PM
Can you please try this function?

Code (fw): Select all Collapse
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 (fw): Select all Collapse
? UNCNAME( <your_file_or_folder_name> )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Reading network pathname
Posted: 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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Reading network pathname
Posted: Fri Jan 17, 2020 01:52 PM
Antonio Linares wrote:Dear Michael,

You may use WNetGetUniversalName()


This function is based on the above suggestion:

Code (fw): Select all Collapse
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 (fw): Select all Collapse
? UNC_NAME( <file_folder_name> )
Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Reading network pathname (solved)
Posted: Fri Jan 17, 2020 07:28 PM
This code has served me well over the years ..

Code (fw): Select all Collapse
// where .exe started from is default directory //

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

msginfo( cDefa )


Rick Lipkin
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Reading network pathname (solved)
Posted: Fri Jan 17, 2020 11:12 PM
Dear Rick, This is not the same?
Code (fw): Select all Collapse
? 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Reading network pathname (solved)
Posted: Sat Jan 18, 2020 02:32 AM
Rick Lipkin wrote:This code has served me well over the years ..

Code (fw): Select all Collapse
// 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 (fw): Select all Collapse
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 (fw): Select all Collapse
? UNCNAME( "L:\FWH\whatsnew.txt" ) // --> "\\GNRDELL\C\FWH\whatsnew.txt"
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Reading network pathname (solved)
Posted: Tue Feb 04, 2020 02: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

Continue the discussion