Umgebungsvariable für USERNAME in LotusScript

  • Hi !
    ich habe ein Script, in dem ich per Klick eine Datei in ein Verzeichnis auf dem PC des Benutzers abspeichern möchte.
    Das Verzeichnis liegt auf dem PC im User-Benutzerverzeichnis . Also "c:\users\<benutzername>\Appdata\Local\....
    Ich weiß nicht, wie ich die Umgebungsvariable vom Benutzernamen hier einbauen muss ?"
    Hab schon diverse Varianten durch. Kommt immer der Fehler, "Path not found".



    "C:\Users\%USERNAME%\AppData\Local\IBM\Notes\Data"
    "C:\Users\%USER%\AppData\Local\IBM\Notes\Data"


    Hat vielleicht jemand eine Idee ?(




    Das ist der Code:


    Option Public
    Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim object As NotesEmbeddedObject
    Dim collection As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim downloadfolder As String
    Set db = session.CurrentDatabase
    Set collection = db.UnprocessedDocuments


    downloadfolder = "C:\Users\%USERNAME%\AppData\Local\IBM\Notes\Data"


    Print "************************************************************************"
    For i = 1 To collection.Count
    Set doc = collection.GetNthDocument( i )
    filen=Evaluate("@AttachmentNames",doc)
    antalfiler=Evaluate("@Attachments", doc)
    UserName=db.FileName


    Print Str(i)+" ("+Str(collection.count)+")"

    If antalfiler(0)>0 Then
    For filecounter=0 To antalfiler(0)-1
    x=x+1
    Print ( filen(filecounter))
    Set Object = doc.GetAttachment( filen(filecounter) )
    If ( object.Type = EMBED_ATTACHMENT ) Then
    fileCount = fileCount + 1
    If Dir(downloadfolder+"\"+ filen(filecounter))="" Then
    extrachar=""
    Else
    extrachar=Left(doc.universalid,4)+"---" 'in case attachment with same name exists in several documents
    End If
    Call object.ExtractFile (downloadfolder+"\"+extrachar+ filen(filecounter) )
    Call doc.Save( True, False )
    End If
    Next filecounter
    End If

    Next
    Msgbox"Es wurden" +Str(fileCount)+ " Dateianhänge auf dem PC im Verzeichnis >\IBM\Notes\Data< gespeichert."

    End Sub

  • Du must mit Environ arbeiten:

    Code
    strUserName=Environ("UserName")
    downloadfolder = "C:\Users\" & strUserName & "\AppData\Local\IBM\Notes\Data"


    Im übrigen steht in %LocalAppData% schon der Pfad bis local inklusive...

  • Weil LotusScript naturgemäß nicht von sich aus OS-Variablen expandiert. Woher soll es auch wissen, ob mit Prozent- oder mit Dollarzeichen gearbeitet wird? So in der Form erwartet das Skript einen Pfad, der in seiner Struktur einen Ordner namens "\%USERNAME\%" (man beachte die escapten Prozentzeichen!) enthält. Den wirst du mit großer Wahrscheinlichkeit auf keinem Windoof-System vorfinden.
    Dazu gibt es aber die Environ Funktion. Environ("Username") sollte den Benutzernamen zurück geben, diesen Return Value wiederum kannst du an "downloadfolder" verfüttern.


    /edit:
    Torsten war schneller :thumbup:

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl

    Einmal editiert, zuletzt von RockWilder ()