【问题标题】:VBS Script tab not nullVBS 脚本选项卡不为空
【发布时间】:2023-03-14 22:46:01
【问题描述】:

之前我已经编写了一个脚本来从一个制表符分隔的文本文件中抓取某些行,第一行以及以下每一行到它自己的 .txt 文件中。 (所以这些 .txt 文件只有 2 行文本)

然后它将移动每个 .txt 文件在给定选项卡中找到的文本,在这种情况下它是 (1)(3)(第二行 - 第四选项卡)

这是第一部分的代码...

Call TwoDimensionArrayTest

Sub TwoDimensionArrayTest

Dim fso
 Dim oFile
 Dim arrline
 Dim arrItem
 Dim i
 Dim arrMain()
 Dim sFileLocation, strResults

 Const forReading = 1

strFolder = "\\nas001\Production\RxCut\In Design Implementation\build\" '"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(strFolder).Files
 If Right(LCase(objFile.Name), 4) = LCase(".txt") Then

 ''# The file contains on each line:
 ''# Text1 (tab) Text2 (tab) Text3 (tab) Text4
 ''# Text5 (tab) Text6 (tab) Text7 (tab) Text8
 ''# etc etc

Set fso = CreateObject("Scripting.FileSystemObject")
  sFileLocation = objFile.Name

  Set oFile = fso.OpenTextFile(objFile.Name, forReading, False)

 Do While oFile.AtEndOfStream <> True
  strResults = oFile.ReadAll
 Loop

 ''# Close the file
 oFile.Close

''# Release the object from memory
 Set oFile = Nothing

''# Return the contents of the file if not Empty
 If Trim(strResults) <> "" Then

  ''# Create an Array of the Text File
  arrline = Split(strResults, vbNewLine)
 End If

 For i = 0 To UBound(arrline)
  If arrline(i) = "" Then
   ''# checks for a blank line at the end of stream
   Exit For
  End If 

  ReDim Preserve arrMain(i)

   arrMain(i) = Split(arrline(i), vbTab)

 Next

      fso.MoveFile sFileLocation, arrMain(1)(3) & ".txt"
 End If 
 Next
End Sub ''# TwoDimensionArrayTest

现在进入下一部分...

好的,我有一个制表符分隔的文本文件,在此文件中,我们在第一行指定了第 5 个标签联合品牌、第 6 个标签三品牌和第 7 个通用标签。

第二行我们有目录路径,无论是联合品牌、三品牌还是通用品牌。

我希望能够将一个给定的文件移动到我们可以称为“group.txt”的任何一个联合品牌、三品牌或通用目录中,具体取决于哪个字段不为空。

我怎样才能做到这一点?如果能够将其合并到指定的最后一个脚本中,那就太好了:

  fso.MoveFile sFileLocation, arrMain(1)(3) & ".txt"

当然,这取决于我上面提到的关于 NOT NULL 字段的内容。

非常感谢任何帮助, 乔

【问题讨论】:

    标签: windows scripting vbscript


    【解决方案1】:

    我的猜测最后是这样的(也许):

    如果不是isNull(Rs("arrMain(1)(4)")) 那么

    设置 sDirectory = "/co-brand"

    如果结束

    如果不是isNull(Rs("arrMain(1)(5)")) 那么

    设置 sDirectory = "/tri-brand"

    如果结束

    如果不是isNull(Rs("arrMain(1)(6)")) 那么

    设置 sDirectory = "/generic"

    如果结束

      fso.MoveFile sFileLocation, sDirectory, arrMain(1)(3) & ".txt" 
    

    【讨论】:

      猜你喜欢
      • 2017-03-02
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多