Page 1 of 1
Reading network pathname (solved)
Posted: Thu Jan 16, 2020 12:00 pm
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.
Re: Reading network pathname
Posted: Thu Jan 16, 2020 12:18 pm
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
Re: Reading network pathname
Posted: Thu Jan 16, 2020 12:45 pm
by driessen
Thanks a lot, Antonio.
Unfortunately, I got an "unknown" external on WNetGetUniversalName.
Re: Reading network pathname
Posted: Thu Jan 16, 2020 12:50 pm
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 )
Re: Reading network pathname
Posted: Thu Jan 16, 2020 1:17 pm
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:"
Re: Reading network pathname
Posted: Thu Jan 16, 2020 1:19 pm
by Antonio Linares
have you tried like this ?
MsgInfo(GetAName("O:"))
Re: Reading network pathname
Posted: Thu Jan 16, 2020 1:51 pm
by driessen
It just returns : "O:"
Re: Reading network pathname
Posted: Thu Jan 16, 2020 9:03 pm
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> )
Re: Reading network pathname
Posted: Thu Jan 16, 2020 11:34 pm
by driessen
Mr. Rao,
Thank you very much. Your solution is working just fine.
Re: Reading network pathname
Posted: Fri Jan 17, 2020 1:52 pm
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
Re: Reading network pathname (solved)
Posted: Fri Jan 17, 2020 7:28 pm
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
Re: Reading network pathname (solved)
Posted: Fri Jan 17, 2020 11:12 pm
by cnavarro
Dear Rick, This is not the same?
Re: Reading network pathname (solved)
Posted: Sat Jan 18, 2020 2:32 am
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"
Re: Reading network pathname (solved)
Posted: Tue Feb 04, 2020 2:24 am
by nageswaragunupudi
Sorry, we were wasting our time re-inventing the wheel.
FWH already has a function
cFileUNC( cLocalName ) --> cUncPath
from FWH 1805