使用WshUserEnv创建文件夹

时间:2014-04-01 08:07:11

标签: vbscript

Sub Copy_TNSNamesORA()
  ' Now look for SQLNET.ora file in %userprofile%\appdata\Roaming and if that exists copy the file to the
  ' the TNSNAMES folder
  Dim fso
  Dim f
  Dim wshShell
  Dim wshUserEnv
  Dim TNSFolder

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Set WshUserEnv = WshShell.Environment("PROCESS")
  TNSFolder = WshUserEnv("TNSNAMES")

  Dim SQLOraTempFileName
  Dim SQLOraLocalFileName
  SQLOraTempFileName = WshUserEnv("userprofile") & "\appdata\Roaming" & "\Oracle\SQLNET.ORA"
  SQLOraLocalFileName = TNSFolder & "SQLNET.ORA"
End Sub

我正在尝试在c\userprofile\appdata\roaming\oracle中创建一个文件夹 使用此代码命名为TNSNAMES。有人可以为我澄清这段代码 TNSFolder = WshUserEnv("TNSNAMES")适合用于创建文件夹吗?

1 个答案:

答案 0 :(得分:2)

根据docs,你可以通过调用FileSystemObject的CreateFolder(surprise!)方法创建一个文件夹。

被盗的演示代码:

Function CreateFolderDemo
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.CreateFolder("c:\New Folder") ' <-- new folder is born
   CreateFolderDemo = f.Path ' <-- return folder spec (string) to caller
End Function

(简单地将包含文件夹规范的字符串分配给变量将复制字符串,但不会自动更改硬盘。)