• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

file name length script

Explorer ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

We have recently changed our server situation and was informed that we now must limit file names to 31 characters or less and no spaces or special characters allowed.

 

I already have a script that i have all my designeres run when a file is finalized that i would like to incorporate this feature into. Does anybody have an existing script or snippet that will throw an alert if these conditions exist?

 

scott

TOPICS
Scripting

Views

660

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 02, 2020 Jun 02, 2020

A sample code for this would be

var f = File("/Users/manan/Desktop/test.zip")
var fName = f.name
if(fName.match(/^[a-zA-Z0-9\.]{1,31}$/))
	alert("Allright")
else
	alert("Error")

 

-Manan

Votes

Translate

Translate
Community Expert ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

If your filename matches the follwing regex it is good

^[a-zA-Z0-9\.]{1,31}$

 

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

A sample code for this would be

var f = File("/Users/manan/Desktop/test.zip")
var fName = f.name
if(fName.match(/^[a-zA-Z0-9\.]{1,31}$/))
	alert("Allright")
else
	alert("Error")

 

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

Thank you....I added an underscore to the acceptable list of characters (my designers like underscores) and it is working great!!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

I marked it as correct because it works great but.....If i could ask for one more little bit of help?

how would i eliminate the alert ("alright")?

I only want an alert if there is more than 31 but just pass thru if less than 31

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

In that case change the code to the following

var f = File("/Users/manan/Desktop/test.zip")
var fName = f.name
if(!fName.match(/^[a-zA-Z0-9\.]{1,31}$/))
	alert("Error")

 

-Manan 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

LATEST

my coworkers think i am much smarter than i am... thanks to people like you!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines