Login  Register

Re: Arrays and string wildcards

Posted by Stein Rørvik on Jan 19, 2021; 7:51pm
URL: http://imagej.273.s1.nabble.com/Arrays-and-string-wildcards-tp5024394p5024398.html

It seems that Array.deleteValue will only delete an exact value, and not deal with substrings nor regular expressions.

You may want to instead use the recently added Array.filter function, which works with regular expressions.
This will extract those files you are interested in, instead of removing those not of interest.
See this example:

dir = getDir("imagej") + "samples/";
print("dir: " + dir);
list = getFileList(dir);
list2 = Array.deleteValue(list, "AuPbSn40.jpg"); //remove this file
list3 = Array.filter(list, ".gif"); //extract all gif files
list4 = Array.filter(list, "(\\d+)"); //extract all files containing numbers
Array.show("lists", list, list2, list3, list4);

It would be useful though if Array.deleteValue would work with regular expressions, when the argument is in parentheses.

Stein

-----Original Message-----
Sent: 19. januar 2021 16:19
Subject: Re: Arrays and string wildcards

Hi Greg,

I put it like that:

dirInput = getDirectory("Choose Input Directory "); list = getFileList(dirInput);
list2 = Array.deleteValue(list,".jpg");
Array.show(list);
Array.show(list2);

It does not work in that way both arrays are the same. "*.jpg" does not make a difference as well.

Regards,
Alex



________________________________
From: JAMES, gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST) <[hidden email]>
Sent: 19 January 2021 15:12
To: [hidden email] <[hidden email]>
Subject: Re: Arrays and string wildcards

Hi Alex,

I think the following macro command will do this:

Array.deleteValue(array, value);

...where value = ".jpg"

Greg.

__________________________________________
Gregory James
Clinical Scientist (Nuclear Medicine)
Department of Physics and Nuclear Medicine City Hospital Dudley Road Birmingham
B18 7QH

0121 507 4043

________________________________
Sent: 19 January 2021 15:04
Subject: Arrays and string wildcards

Dear listers,

I am writing a macro with which I want to correct certain files in a directory and convert them to different formats. Some of files are not readable by ImageJ or Bioformats/Fiji and need to be excluded from opening. Others may need different operations depending on file type.
If I get the array of filenames from this directory can I delete array elements using not exact string but a wildcard (like "*.jpg")?

Or is there any other way to make conditions based on file type?

Thank you in advance!

Best regards,
Alex Mironov



--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986892009%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=Wn47WqKjiN5y%2BQZQtCpRDdHMdCK%2FMBdvaKLgoU14RDo%3D&amp;reserved=0



This message originated from outside of NHSmail. Please do not click links or open attachments unless you recognise the sender and know the content is safe.



********************************************************************************************************************

This message may contain confidential information. If you are not the intended recipient please inform the sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services.

For more information and to find out how you can switch, https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fportal.nhs.net%2Fhelp%2Fjoiningnhsmail&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986901958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=E3A7JgUzKQfH%2BfKl3BSYXOI2qAAPG2aAFa9p87hMj8o%3D&amp;reserved=0


--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986901958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=F2Kx8MzwKPwjz88MlYovUCmCx%2Fw78GDzmikk8z6xghk%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986901958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=F2Kx8MzwKPwjz88MlYovUCmCx%2Fw78GDzmikk8z6xghk%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html