Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi !
Can anyone help me ?
How would you declare one variable that will contain 2 other variables in vbscript ?
Right now, I have ;
SearchPath1 = "C:\Temp1"
SearchPath2 = "C:\Temp2"ResultSearchPath = SearchPath1 and SearchPath2
But I get a Type mismatch: 'Temp2" error message
Thanks
CR

@echo off
setLocal EnableDelayedExpansionset v1=this
set v2=that
set v3=!v1!!v2!
echo v3 is now set to !v3!==========================
NOTE: In your example, the SET has spaces on both sides of =, which will lead to unexpected, and usually unpleasant, consequences
=====================================
If at first you don't succeed, you're about average.M2

Thanks for your help M2 but now I get this syntax error at the line
set v3=!v1!!v2!Probably vbscript doesn't like these (!!) exclamation marks

I didn't realize it was VBS. Wait for one of the other guys.
=====================================
If at first you don't succeed, you're about average.M2

The concatenation operator is &.
ResultSearchPath = SearchPath1 & SearchPath2
That would give you C:\Temp1C:\Temp2. This may not be what you want, but I can only work with what I'm given.

I haven't used VBS before, but if it similar to VB, then try using &
var1 = "string1"
var2 = "string2"
var3 = var1 & var2If you need some way to break them up again, then try
var3 = var1 & some_deliminator & var2
The deliminator should be something that isn't in either string or something VBS wouldn't choke on such as an escaped or html type special char.
HTH

Thanks for replies guys, I should have explained what Im trying to do. I want to make one string to search two folders for a file.
Here is what I have so far but I get an error msg at the last line of the script saying "Path not found"
Dim FileName
Dim FileName2
Dim FolderReDim Location(0)
FileName="test.txt"
FileName2="Test.txt"path1="c:\temp"
path2="c:\temp2"
PFolder=path1&path2Set System=CreateObject("Scripting.FileSystemObject")
Call FindFile(PFolder)
Sub FindFile(ThisFolder)
Dim File
Dim Folder
For Each Folder In System.GetFolder(ThisFolder).SubFoldersThe last script line above is where I get the error message "Path not found"
Any help appreciated.
Thanks
CR

You need to think very clearly about what exactly you are doing at each step. What are you passing to Sub FindFile? The sub expects a string variable that names a single folder. You passed it "c:\temp1c:\temp2". There is no such folder on your system.
Also, the documentation for System.GetFolder says it expects the name of a single folder.
You need to think about exactly how you are going to "combine" the two folders. What does combining actually mean?
For your application, you can put all the folder names into an array, and put a loop where you call FindFile each time through the loop.

Thanks for your reply Klint
Actually, all I'd like to do is to search for a file in two folders (c:\temp and c:\temp2) one after the other.
I know that this can be done in vbscript, I just don't know how to set one variable that will hold the path of these two folders.
Thanks
CR

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |