Reading network pathname (solved)
Reading network pathname (solved)
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.
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Reading network pathname
Dear Michael,
You may use WNetGetUniversalName() or adapt this code to Harbour:
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
Re: Reading network pathname
Thanks a lot, Antonio.
Unfortunately, I got an "unknown" external on WNetGetUniversalName.
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Reading network pathname
Michael,
Please try these ones:
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 )
Re: Reading network pathname
Sorry, Antonio,
It doesn't work.
I tried this :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:"
It doesn't work.
I tried this :
Code: Select all
MsgInfo( GetAName( "O" ) )
MsgInfo( GetDriveLetter( "\\COMPUTER3\C\SOFTWARE\JUDA\DATA" ) )
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Reading network pathname
have you tried like this ?
MsgInfo(GetAName("O:"))
MsgInfo(GetAName("O:"))
Re: Reading network pathname
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Reading network pathname
Can you please try this function?
Usage:
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
Code: Select all
? UNCNAME( <your_file_or_folder_name> )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Reading network pathname
Mr. Rao,
Thank you very much. Your solution is working just fine.
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
Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Reading network pathname
This function is based on the above suggestion:Antonio Linares wrote:Dear Michael,
You may use WNetGetUniversalName()
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 ); }
}
Code: Select all
? UNC_NAME( <file_folder_name> )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Rick Lipkin
- Posts: 2397
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Reading network pathname (solved)
This code has served me well over the years ..
Rick Lipkin
Code: Select all
// where .exe started from is default directory //
cFILE := GetModuleFileName( GetInstance() )
nSTART := RAT( "\", cFILE )
cDEFA := SUBSTR(cFILE,1,nSTART-1)
msginfo( cDefa )
Re: Reading network pathname (solved)
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.
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.
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Reading network pathname (solved)
Mr. RickRick Lipkin wrote:This code has served me well over the years ..
Rick LipkinCode: Select all
// where .exe started from is default directory // cFILE := GetModuleFileName( GetInstance() ) nSTART := RAT( "\", cFILE ) cDEFA := SUBSTR(cFILE,1,nSTART-1) msginfo( cDefa )
Simpler ways of doing:
Code: Select all
cFilePath( hb_argv( 0 ) ) // Christobal
// OR
cFilePath( ExeName() )
For example, in my case:
Code: Select all
? UNCNAME( "L:\FWH\whatsnew.txt" ) // --> "\\GNRDELL\C\FWH\whatsnew.txt"
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Reading network pathname (solved)
Sorry, we were wasting our time re-inventing the wheel.
FWH already has a function
cFileUNC( cLocalName ) --> cUncPath
from FWH 1805
FWH already has a function
cFileUNC( cLocalName ) --> cUncPath
from FWH 1805
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India