Rename file with condition

Hello

I try to rename all the files from a specific Path. To do this I check if the files contains a specific word at the end, as example “Maxillary”. The problem happens when there are 2 or more files that can fit the same renaming method.

Is there any expression or function that can count me the number of files from Path that contains a specific word?

As example I try to rename the “Maxilary” file to something that has “_Upper” at the end. In my example here I already have it so I dont want to rename that file. So i want to build and IF statement that will count my files that contains “Upper”. If the number is bigger than 1 then i wont make the change and continue to next files.

image

Is that going to work?

FilePath is my path string variable

Hi,

I think the following might be better because the above evaluate not only filename but also all path string, and as windows filesystem is case-insensitive, Upper and upper is same, for example.

Directory.GetFiles(filePath).Where(Function(n) Path.GetFileNameWithoutExtension(n).ToUpper.Contains("UPPER")).Count=0

If target string always exists at the end of filename, EndsWith method might be better.

Regards,

@Paul_Andrei_Turcu
Count= System.IO.Directory.GetFiles(fileListPath,“Upper”).Count
put if and check count

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.