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: http://imagej.nih.gov/ij/list.html |
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 ________________________________ From: Aleksandr Mironov <[hidden email]> Sent: 19 January 2021 15:04 To: [hidden email] <[hidden email]> 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: http://imagej.nih.gov/ij/list.html 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://portal.nhs.net/help/joiningnhsmail -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
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 ________________________________ From: Aleksandr Mironov <[hidden email]> Sent: 19 January 2021 15:04 To: [hidden email] <[hidden email]> 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: http://imagej.nih.gov/ij/list.html 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://portal.nhs.net/help/joiningnhsmail -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear Aleksandr,
The following code should make the deal: dirInput = getDirectory("Choose Input Directory "); list = getFileList(dirInput); for (i = list.length - 1; i >= 0; i--) if(endsWith(list[i], ".jpg")) list = Array.deleteIndex(list, i); // list = Array.deleteValue(list, list[i]); Array.show(list); I have left both the Array.deleteIndex and Array.deleteValue options for you to choose your preferred one. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 42 89 ----- Le 19 Jan 21, à 16:19, Aleksandr Mironov [hidden email] a écrit : 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 ________________________________ From: Aleksandr Mironov <[hidden email]> Sent: 19 January 2021 15:04 To: [hidden email] <[hidden email]> 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: http://imagej.nih.gov/ij/list.html 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://portal.nhs.net/help/joiningnhsmail -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by AAM71
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&data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986892009%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=Wn47WqKjiN5y%2BQZQtCpRDdHMdCK%2FMBdvaKLgoU14RDo%3D&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&data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986901958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=E3A7JgUzKQfH%2BfKl3BSYXOI2qAAPG2aAFa9p87hMj8o%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986901958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=F2Kx8MzwKPwjz88MlYovUCmCx%2Fw78GDzmikk8z6xghk%3D&reserved=0 -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Cstein.rorvik%40sintef.no%7C2a99af0a60da4fdfea6708d8bc8dad3d%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637466663986901958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=F2Kx8MzwKPwjz88MlYovUCmCx%2Fw78GDzmikk8z6xghk%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by CARL Philippe (LBP)
Dear Philippe!
Thanks a lot! if(endsWith(list[i], ".jpg")) - is my saviour! Best regards, Alex ________________________________ From: CARL Philippe (LBP) <[hidden email]> Sent: 19 January 2021 15:55 To: [hidden email] <[hidden email]> Subject: Re: Arrays and string wildcards Dear Aleksandr, The following code should make the deal: dirInput = getDirectory("Choose Input Directory "); list = getFileList(dirInput); for (i = list.length - 1; i >= 0; i--) if(endsWith(list[i], ".jpg")) list = Array.deleteIndex(list, i); // list = Array.deleteValue(list, list[i]); Array.show(list); I have left both the Array.deleteIndex and Array.deleteValue options for you to choose your preferred one. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 42 89 ----- Le 19 Jan 21, à 16:19, Aleksandr Mironov [hidden email] a écrit : 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 ________________________________ From: Aleksandr Mironov <[hidden email]> Sent: 19 January 2021 15:04 To: [hidden email] <[hidden email]> 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: http://imagej.nih.gov/ij/list.html 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://portal.nhs.net/help/joiningnhsmail -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |