Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with UNC paths 2

Status
Not open for further replies.

Jerim65

Technical User
Aug 8, 2010
99
AU
I spoke about this in other threads but still have a problem to work out.

I am converting all network paths to UNC as suggested previously.

I am dealing with file paths - held in fields in 2 tables.

The target path in table 1 may be expressed as - example

1 \\NASSERVER209\MYUSERDATA\EXHIBITS\COLDAN\95TH.GIF

or

2 T:\EXHIBITS\COLDAN\95TH.GIF

with the aid of table 2 - a lookup table of drivetypes - I have

T: is \\NASSERVER209\MYUSERDATA

So I want to convert #2 to #1 so to speak


In plain language

Test if this part of #1 - \\NASSERVER209\MYUSERDATA is in the lookup table as in #2.

Lookup table:-

Select drives

Index On Upper(cPath) Tag cPaths
Set Order To cPaths

in file list I will have an target entry in the paths field
\\NASSERVER209\MYUSERDATA\EXHIBITS\COLDAN\95TH.GIF

How do I get \\NASSERVER209\MYUSERDATA\ from the target path to make a test for existence in the drives table cPath field?

Hope this complex ( for me ) description is clear enough.

Thanks

Coldan




 
Why? you ould actually locate for paths beginning with "T:" and replacing "T:" with the UNC path, that's it.

Code:
Set Ansi Off
Update tablePaths Set cPath = Strtran(cPath,"T:","\\NASSERVER209\MYUSERDATA",1,1) Where Upper(cPath)="T:" And File(Strtran(cPath,"T:","\\NASSERVER209\MYUSERDATA",1,1))

Through Ansi being off the expression Upper(cPath)="T:" actually does find records with
cPath starting with "T:" making use of the index you have.

And instead of the litarals "T:" and "\\NASSERVER209\MYUSERDATA" you can also use ALLTRIMmed values of the lookup table you have of drives, eg that would be Strtran(cPath,Alltrim(drives.driveletter),Alltrim(drives.uncpath),1,1) and you'd add a outer scan..endscan loop over the drives lookup table.

Bye, Olaf.
 
Olaf,

I'm sorry I don't understand your code

Overall - there could be several mapped drives on the users PC. So 'hard coding' won't work.

Before I go further

Set Ansi Off
Update tablePaths Set cPath = Strtran(cPath,"T:","\\NASSERVER209\MYUSERDATA",1,1) Where Upper(cPath)="T:" And File(Strtran(cPath,"T:","\\NASSERVER209\MYUSERDATA",1,1))

What is tablePaths? How does this work - in plain English please.

Coldan

 
Coldan,

you didn't specify how the table storing the paths is named, you just did specify the lookup table with drive letters and their corresponding unc paths is called "drives". At least that's as I understand it.

So you need to change tablePaths to your table name containing the cPath field, perhaps that's "paths".

You can't expect us to remember your setup and table names from thread to thread or look that up, I'm not only posting here at tek-tips and also have a lot of own everyday work to do and you're not the only questioner here.

On the other side I think choosing the "tablePaths" pseudo teable name for the non given table name should be fairly easy to understand and translate to your situation.

Regarding the question "How does this work?":

1. An UPDATE is an SQL command updating a table, the Set clause sets a field to a value, in this case the cPath field value, as that's where I assume you want to convert paths beginning with drive letters with their UNC analogon.

2. Where Upper(cPath)="T:" in conjunction with Ansi Off is finding all records with cPath starting with "T:".

3. File() is a function finding out if a file exists and returning .T. or .F. (true or false) respectively, so the update only updates records where your condition is met, that the file exists under the changed full unc file name.

4. In regard to not working with the hard coded literals, I already said you can write Alltrim(drives.driveletter) instead or whereever the drive letter comes from and you can write Alltrim(drives.uncpath) instead of "\\NASSERVER209\MYUSERDATA" so the code only stands as an example, you don't need to hard code this.

If you're given functions like StrTran() or File() you can easily look them up in the foxpro help, too.

Bye, Olaf.
 
ad 2)
I'm using UPPER(cPath) in the where clause instead of cPath, as you say you have an index on UPPER(cPath) and that takes advantage of that.

And to process all drives you can do this:
Code:
Select drives
Scan
  Update ....
Endscan

So you will do the update sql for each record of drives. You could also do
Code:
Update paths ... FROM drives WHERE...

Especially if you replaced the hard coded values with the fields of the drives table.

Bye, Olaf.
 
Coldan,

This routine may help. You will have to adapt it to you needs as it is just an example, but pay special attention to 'Caption' and 'ProviderName' values:
Code:
IF USED("drives")
   USE IN drives
ENDIF 
CREATE CURSOR drives (propname c(20), propval c(35))

oManager = GETOBJECT("winmgmts:")

om = ;
   oManager.InstancesOf("Win32_MappedLogicalDisk")

FOR EACH Adapter IN om
   FOR EACH Property IN Adapter.Properties_ 
      INSERT INTO drives (propname, propval ) VALUES (Property.name , TRANSFORM(NVL(Property.Value, "NULL" )))
   NEXT 
NEXT 
RETURN


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Olaf and Dave and others

With your help I have managed to get what I think is required in my app to deal with UNC paths. I am waiting to see if it works for a user.
Many thnaks
Coldan
 
My user has confirmed that my routine works correctly.

Thanks everyone...

Coldan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top