I am also not an admirer of a mapped drive as that will lead to a lot of problems later such as giving users easy access to the folder for the app, issue of sleeping mapped drives, or workstations using different mapped drive letters.
Anyway, this is so in case you have mapped drives in your workstations and you want to get a fullpath() of a file using GETFILE(), then you can always get the UNC path if file is coming from a network drive. For instance, if you have a mapped drive Z:\ and you point to a file there, instead of getting Z:\myFile.jpg you will get \\192.168.1.1\YourFolder\myFile.jpg or something like that instead; where drive Z: will be replaced by the actual UNC path.
Here is a code for that:
Local lcFile
lcFile = GETUNC(Getfile())
Messagebox(m.lcFile)
********
Function GETUNC(cFile)
********
Local lcFullPath, lcDrive, lcUNC, lnSize
If !Empty(m.cFile)
lcDrive = Justdrive(m.cFile)
lcFullPath = Fullpath(m.cFile)
If Drivetype(m.lcDrive) = 4
lnSize = 600
lcUNC = Space(lnSize)
Declare Integer WNetGetConnection
In WIN32API String @lcDrive, String @lcUNC, Integer @lnSize
WNetGetConnection(@lcDrive, @lcUNC, @lnSize)
lcFullPath = Strtran(m.lcFullPath,m.lcDrive,Left(m.lcUNC,Len(Alltrim(m.lcUNC))-1))
Clear Dlls WNetGetConnection
Endif
Endif
Return(m.lcFullPath)
Cheers!
No comments:
Post a Comment