Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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