File path validation

William08
Tera Contributor

Hi all,

 

Need a help on file path validation for below patterns. Could anyone please help on this

 

x:\File

\File\File\ or
\File\File or
\File\\File etc

 

Thanks in advance

1 ACCEPTED SOLUTION

Hi @William08 , 

 

I have validated the below code in background script can you please check once

var patterns = [
  /^E:[\\\/].+[\\\/]?$/,
  /^[a-zA-Z0-9_]+([\\\/][a-zA-Z0-9_]+)+[\\\/]?$/,
];
var filePaths = 'E:\\Test/data1/data2/data2/data2/';
gs.print(filePaths);
var pattern = patterns[0]; // Select the first pattern
if (pattern.test(filePaths)) {
  gs.print("matched");
} else {
  gs.print("mismatched");
}

 Output :

*** Script: E:\Test/data1/data2/data2/data2/
*** Script: matched

 

SaiShravan_0-1686234349016.png

 

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

6 REPLIES 6

Hi @William08 , 

 

I have validated the below code in background script can you please check once

var patterns = [
  /^E:[\\\/].+[\\\/]?$/,
  /^[a-zA-Z0-9_]+([\\\/][a-zA-Z0-9_]+)+[\\\/]?$/,
];
var filePaths = 'E:\\Test/data1/data2/data2/data2/';
gs.print(filePaths);
var pattern = patterns[0]; // Select the first pattern
if (pattern.test(filePaths)) {
  gs.print("matched");
} else {
  gs.print("mismatched");
}

 Output :

*** Script: E:\Test/data1/data2/data2/data2/
*** Script: matched

 

SaiShravan_0-1686234349016.png

 

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hi @Sai Shravan 

 

Its working thanks a lot