Reference - https://docs.kentico.com/api9/content-management/media-libraries
Modified the reference code.
// Gets the media library
MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo("NewLibrary", SiteContext.CurrentSiteName);
if (library != null)
{
// Gets all .png files from the "NewFolder" folder of the specified media library
var mediaFiles = MediaFileInfoProvider.GetMediaFiles()
.WhereEquals("FileLibraryID", library.LibraryID)
.WhereStartsWith("FilePath", "NewFolder");
// Loops through individual media library files
foreach (MediaFileInfo mediaFile in mediaFiles)
{
// Your logic
}
}