I apologies if this question has been answered in another post but I can't seem to figure this out. What I'm trying to do is take a directory path that I have that is selected through FolderBrowserDialog. The folder that that I select is then processed and then displays all of the files within the folder selected and the files in the subDirectory. All that is done... What I want to do is take the files within the folder selected and compare it to the hex of the file to only show files such as PDF or JPG. I saw a few things that say that I need to convert to binary which I believe I have done. Then convert that Binary to hex. So I need to figure out how to take the binary and convert it to a hex from the directory path that is chosen. here is a sample of code of what I have
// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
byte[] fileBytes = File.ReadAllBytes(path);
StringBuilder sb = new StringBuilder();
foreach (byte b in fileBytes)
{
sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
}
Console.WriteLine("Test {0}",sb);
Console.ReadLine();
}
Like I said, I believe that I have the code to convert to binary correct, it just turns the entire directory path to binary which I'd prefer to just be the file and not the whole path. I can't seem to find out how to successfully convert the binary to hex so that I can exclude files other than PDF and JPG. Sorry for this being so long.
Edit: I need to compare the file signature of a file and compare it to JPG which starts with 0xFFD8 and PDF which starts with 0x25504446. I need to determine whether or not a file is PDF or JPG using those values. If I got my vocab wrong I apologize. If anyone has a better idea on how I should go about comparing these two using 0x25504446 and 0xFFD8 I'm all ears. Sorry if I worded any of the description weirdly.