Search code examples
vbscriptstring-concatenation

Concatenate variable + string inside of a Join(Array())


I have the script below that make a referer to two files names and the second file name is present inside a Join(Array()) between "", but I'm needing use a folder name that already was defined before in a variable, for create a new file inside this folder and that will store the final result produced by this script:

    Option Explicit

Const LOCAL_APPLICATION_DATA = &H1c&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(LOCAL_APPLICATION_DATA)
Set objFolderItem = objFolder.Self

Set colItems = objFolder.Items

Dim sCurDir
Dim sFina

For Each objItem in colItems

    If InStr(1, objItem.Name, "Google") > 0 Then

      sCurDir =  objFolderItem.Path + "\" + objItem.Name + "\Chrome\User Data\Default\"
      sFina = "History"

      Exit For

    End If
Next

    Function qq(s) : qq = """" & s & """" : End Function

    Const cnHidden = 0
    Const cbWait = True

    Dim sCmd : sCmd = Join(Array( _
         "%comspec%" _
       , "/c" _
       , "sqlite3.exe" _
       , "-csv" _
       , qq("..\data\History") _
       , qq("SELECT id, url FROM urls LIMIT 5") _
       , ">.\urls.csv" _
    ))
    WScript.Echo sCmd
    CreateObject("WScript.Shell").Run sCmd, cnHidden, cbWait
    WScript.Echo "Done"

Then, if I try replace ">.\urls.csv" by for example """"+sCurDir + "new.csv""" the file don't is created. How solve it?


Solution

  • Solved:

        Dim strUser
        strUser = CreateObject("WScript.Network").UserName
    
        ...
    
        Dim sCmd : sCmd = Join(Array( _
                 "%comspec%" _
               , "/c" _
               , "sqlite3.exe" _
               , "-csv" _
               , qq(sCurDir + sFina) _
               , qq("SELECT url FROM urls") _
               , ">C:\Users\"+strUser+"\AppData\Local\Google\Chrome\new.csv" _
            ))