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

Determine IF and WHERE in a string an Alpha character is found

Participant ,
Oct 05, 2022 Oct 05, 2022

Copy link to clipboard

Copied

Hi folks,

I am looking for a way to determine if and where an alpha character may be found in a string.

I am trying to put a script together that would read the strings, which happen to be SKU numbers, from an Excel file. It would then determine what folder on a server to search in to retrieve a file. We have complex folder structure that is broken down into subfolders. Being able to know where the Alpha falls in the SKU# (file name) and report what the Alpha character would help direct me to the right place. Searching the terrabytes of data from the root directory is too slow.

My end goal is something along the lines of :

1) Read the first string in column A in csv file.
2) Check if string has an alpha character and in what position it is. Currently SKUs are 5 characters long.

3) If an alpha is found, report the position and what letter it is to be used to determine the correct directory path to check for the file.

4) Download/copy file to a folder location.

 

Theses are examples of strings and their associated folder structure. 

12345    no alpha

F1234   position 1   has folders: [alpha]2000-[alpha]2999 etc.   D2000-D2999

1R234   position 2   has folders: 1C000-1C999, 1D000-1D999 etc.
12Y34   position 3   has folders: 10A-19Y, 20A-29Y etc.

123X5.  position 4.  has folders:  000A0-099A9, 100A0-199Z9 etc.

 

Any help would be appreciated, thanks!

 

TOPICS
Actions and scripting

Views

715

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 2 Correct answers

Community Expert , Oct 05, 2022 Oct 05, 2022

I would use regex - .test()

 

var skuCode = "12345";

if (/\b\d{5}\b/i.test(skuCode) === true) {
    alert("There is no alpha character, there are only 5 digits!");

} else if (/\b[a-z]\d{4}\b/i.test(skuCode) === true) {
    alert("There is an alpha character at position 1!");

} else if (/\b\d[a-z]\d{3}\b/i.test(skuCode) === true) {
    alert("There is an alpha character at position 2!");

} else if (/\b\d{2}[a-z]\d{2}\b/i.test(skuCode) === true) {
    alert("There is an alpha character at posi
...

Votes

Translate

Translate
Community Expert , Oct 05, 2022 Oct 05, 2022

Stephen got a version that works. Here's my way with the loop:

 

var sku = '24Y23'
var pos = 'none'
for (var i =0;i<5;i++){
    var digit = sku.substr (i, 1);   
    if(isNaN(Number(digit))){
        pos = i+1
        break;
        }
    }
alert(pos)

 

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Your excel file could most likely be formatted in a better manner to make it easier to search. It could then be converted to a tab separated file and imported into the code as an array that could be searched.

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
Participant ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Chuck, that Excel file is just my structual analysis of the directory structure. The CSV file that would be used would be more like this, attached. These products are to be placed in background scenes.Up to 5 will be chosen per background. I am likely to save all 5 as a group in a folder named for the primary sku [Sku1] in the CSV. Does this make more sense?

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Sort of. Everything can be automated. While I was working, some of our photographers had to shoot parts that came with paper work with barcodes. With the scanner that produced a text file, we extraced that info and put it into the image's metadata.

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
Participant ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

The onlything I have done with Metadata was to transfer keywords to description for about 300K files because the DAM we had needed it. I'm sure there is a lot more I could do with Metadata. Our photographers are entering data such as sku, product skus in the shot and other data manually. I created an Excel document that concatonates product info into a string so they can copy/paste it easily. It would be nice if we could just scan products to enter the data.

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Most the images we were entering info manually: descriptions, but doing that in Bridge was pretty easy. Then we could pull the description field in the meta data and insert that in the photo.

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Got a chuckle on your user name.

FB_IMG_1665077210171.jpg

 

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
Participant ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

Back in 1999 I attended my first NAPP conference. Scott Kelby was presenting in Los Angeles. YOU are the real thing! Congrats on the awards! Hmmm...  Or did you just Photoshop them? LOL

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 ,
Oct 06, 2022 Oct 06, 2022

Copy link to clipboard

Copied

LOL, no, they're the real deal. Had a few others as runners up.

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