Reading network pathname (solved)

Post Reply
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Reading network pathname (solved)

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Reading network pathname

Post by Antonio Linares »

Dear Michael,

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

Code: Select all

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
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Post by driessen »

Thanks a lot, Antonio.

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

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Reading network pathname

Post by Antonio Linares »

Michael,

Please try these ones:

Code: Select all

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
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Post by driessen »

Sorry, Antonio,

It doesn't work.

I tried this :

Code: Select all

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Reading network pathname

Post by Antonio Linares »

have you tried like this ?

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

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Post by driessen »

It just returns : "O:"
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Reading network pathname

Post by nageswaragunupudi »

Can you please try this function?

Code: Select all

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

? UNCNAME( <your_file_or_folder_name> )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Reading network pathname

Post by driessen »

Mr. Rao,

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

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Reading network pathname

Post by nageswaragunupudi »

Antonio Linares wrote:Dear Michael,

You may use WNetGetUniversalName()
This function is based on the above suggestion:

Code: Select all

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

? UNC_NAME( <file_folder_name> )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Reading network pathname (solved)

Post by Rick Lipkin »

This code has served me well over the years ..

Code: Select all

// 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
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Reading network pathname (solved)

Post by cnavarro »

Dear Rick, This is not the same?

Code: Select all

? cFilePath( hb_argv( 0 ) )
 
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Reading network pathname (solved)

Post by nageswaragunupudi »

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

Code: Select all

// 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

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

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

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

Re: Reading network pathname (solved)

Post by nageswaragunupudi »

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
Post Reply