Highlighted

file name length script

Community Beginner ,
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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

318

Likes

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

file name length script

Community Beginner ,
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

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

319

Likes

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
Jun 02, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Jun 02, 2020 1
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Jun 02, 2020 0
Community Beginner ,
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!!!!!

Likes

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
Reply
Loading...
Jun 03, 2020 0
Community Beginner ,
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

Likes

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
Reply
Loading...
Jun 03, 2020 0
Adobe Community Professional ,
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 

Likes

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
Reply
Loading...
Jun 03, 2020 0
Community Beginner ,
Jun 03, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jun 03, 2020 0