Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

vbscript search for string within string not working if filename contains a dash / hyphen

$
0
0

Hello, 

I am hoping this is just something simple I missed but everything tried so far doesnt work.

I have a folder containing a list of files.  What I need to do is read a text based file that contains a list of file names and search the folder for any file that contains the entry from the text file.

So for example my text file contains the following entry

file1

 

My test folder is C:\test    This folder contains the following files

Testfile1.exe

Testfile2.exe

The goal is a script that says search the folder c:\test for any file that contains "file1" and if its found then delete that file from the folder.

So from the example above the result should be that Testfile1.exe contains the word "file1" so it gets deleted.  The folder should only contain Testfile2.exe after the script runs.

Here is where I need help.   I can get the above to work correctly several different ways .  My problem is that the actual file names I will be using contain a dash,      5-file1.exe

No matter what I do I cannot get the same script to work if the filename contains a dash.  I think it has to do with the script engine reading it as a math operator or some other critera but it certainly does not like the dash.

I did not include my sample code because I am open to any suggestions.  Read the text file line by line,  read into an array or dictionary,   anything that works is fine by me.

If anyone can figure this out I would really appreciate it.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>