简体   繁体   English

VBS脚本选项卡不为空

[英]VBS Script tab not null

Earlier I have made a script to grab certain lines from a tabbed delimited text file, first row with each of the following rows into its own .txt file. 早些时候,我已经编写了一个脚本来从带标签的定界文本文件中抓取某些行,第一行和随后的每一行都放入自己的.txt文件。 (so these .txt files are only 2 rows of text) (因此这些.txt文件仅是两行文本)

Then it would move each .txt file by what text it found in the given tab in this case it was (1)(3) (second row - forth tab) 然后,它将每个.txt文件移动在给定标签中找到的文本,在这种情况下为(1)(3)(第二行标签)

here is the code for the first part... 这是第一部分的代码...

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

Now moving on to the next part... 现在转到下一部分...

ok I have a tabbed delimited text file and in this file we have specified on first row 5th tab co-brand, 6th tab tri-brand, and 7th generic. 好的,我有一个制表符分隔的文本文件,在该文件中,我们在第一行中指定了第5个标签联合品牌,第6个标签三品牌和第7个通用标签。

second row we have the directory path to whichever it maybe either co-brand, tri-brand or generic. 第二行中有目录路径,无论目录是联合品牌,三品牌还是通用品牌。

What I want to be able to do is move a given file we can call "group.txt" to either of those co-brand, tri-brand, or generic directories depending upon which field is NOT NULL. 我想要做的就是将给定的文件(我们可以将其称为“ group.txt”)移动到这些联合品牌,三品牌或通用目录中,具体取决于哪个字段为非NULL。

How can I accomplish this? 我该怎么做? Would be nice to just be able to incorporate this into the last script towards the end where specified: 能够将其合并到指定位置的最后一个脚本中将是很好的:

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

of course would depend from here what I mentioned above about the NOT NULL field. 当然,这将取决于我在上面提到的有关NOT NULL字段的内容。

Any help is greatly appreciated, Joe 乔非常感谢任何帮助

my guess is something like this at the end (maybe): 我的猜测是这样的结尾(也许):

If not isNull(Rs("arrMain(1)(4)")) Then 如果不是isNull(Rs(“ arrMain(1)(4)”))然后

Set sDirectory = "/co-brand" 设置sDirectory =“ / co-brand”

End If 万一

If not isNull(Rs("arrMain(1)(5)")) Then 如果不是isNull(Rs(“ arrMain(1)(5)”))然后

Set sDirectory = "/tri-brand" 设置sDirectory =“ / tri-brand”

End If 万一

If not isNull(Rs("arrMain(1)(6)")) Then 如果不是isNull(Rs(“ arrMain(1)(6)”))然后

Set sDirectory = "/generic" 设置sDirectory =“ / generic”

End If 万一

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM