Salir
  • Comunidad global
    • Idioma:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

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

Participante ,
Oct 05, 2022 Oct 05, 2022

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!

 

TEMAS
Acciones y scripts
3.5K
Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines

correct answers 2 respuestas correctas

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
...
Traducir
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)

 

Traducir
Adobe
Community Expert ,
Oct 06, 2022 Oct 06, 2022

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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Participante ,
Oct 06, 2022 Oct 06, 2022

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?

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Participante ,
Oct 06, 2022 Oct 06, 2022

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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

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.

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

Got a chuckle on your user name.

FB_IMG_1665077210171.jpg

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Participante ,
Oct 06, 2022 Oct 06, 2022

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

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022

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

Traducir
Informe
Directrices de la comunidad
Sé amable y respetuoso, muestra títulos de crédito de la fuente de contenido original y busca duplicados antes de publicar. Más información
community guidelines