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

HELP: Enumerating Files in folder -> RegExp-ing special patern file names

$
0
0

Hi everybody.

 I’m Testing this piece of Jscript code:

 

Function enFilesInFldr(folderspec){
var objFSO = new ActiveXObject("Scripting.FileSystemObject");  // FSObject
var f = objFSO.GetFolder(folderspec);
var fc = new Enumerator(f.files); // list all files
var re = new RegExp("[BCP_]+[\w]+[\w]+[\.]+[b]+[a]+[t]","i");  // regexp for ‘BCP_name_date.bat’
for (; !fc.atEnd(); fc.moveNext()){
var s = fc.item() + ""; // make string
      alert(s + "\n" + typeof(s) + "\n" + s.search(re));  // test 
//if (s.lastIndexOf('.log') != -1){  // test only extension -> OK
if (s.search(re) != -1){  // test RegExp -> ERROR

 // ……………Do Something …………….. 

}}}

Purpose is to find all files named whit this pattern: BCP_name_date.bat’ (BaCkuP)

Like

BCP_abv_10102010.bat

BCP_test_65231.bat

BCP_test2_0000000.bat’

BCP_third_date.bat’

In test folder have file with name “BCP_test_10102013.bat”, but still getting result -1.

 Any help?



Viewing all articles
Browse latest Browse all 15028

Trending Articles



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