ExifTool Forum

ExifTool => Developers => Topic started by: Brainbow on July 24, 2024, 04:23:24 PM

Title: C#: Problem with filepath in Commandline
Post by: Brainbow on July 24, 2024, 04:23:24 PM
Hello,

I am writing a simple application in C# to remove ratings of my images using SharpExifTool.

string exifToolArguments ="-rating= -ratingpercent= C:\\Users\\Anon\\Desktop\\TestFolder\\test.png"

using (var exiftool = new SharpExifTool.ExifTool())
{
  await exiftool.ExecuteAsync(exifToolArguments);
}

This Codeexample is working, but if my targetpath has empty spaces in its full pathname, the path can not be recognized by the program.
The path also doesn't like quotation marks at all. If I use \"C:\\Users\\Anon\\Desktop\\TestFolder\\test.png\", even the path without spaces won't work.

How can I fix that?
Thanks in advance
Title: Re: C#: Problem with filepath in Commandline
Post by: Phil Harvey on July 24, 2024, 08:22:11 PM
I'm guessing you should escape the quotes with a backslash.

- Phil
Title: Re: C#: Problem with filepath in Commandline
Post by: Brainbow on July 24, 2024, 08:26:25 PM
Thanks for your reply.

You mean like this?
string exifToolArguments ="-rating= -ratingpercent= \"C:\\Users\\Anon\\Desktop\\TestFolder\\test.png\"";

I've already tried, doesn't even work on a path without spaces like this.
Title: Re: C#: Problem with filepath in Commandline
Post by: Phil Harvey on July 24, 2024, 08:33:26 PM
Oh well.  You should ask the SharpExifTool people how to pass arguments with special characters.

- Phil
Title: Re: C#: Problem with filepath in Commandline
Post by: Brainbow on July 24, 2024, 09:04:13 PM
You're right.

When i use your external Tool exiftool.exe and start it with my C# Code, it works like a charm.

string exifToolArguments = "-overwrite_original -rating= -ratingpercent= \"C:\\Users\\Anon\\Desktop\\TestFolder\\test.png\"";

var process = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = @"C:\Users\Anon\Downloads\Compressed\exiftool\exiftool.exe",
        Arguments = exifToolArguments,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        UseShellExecute = false,
        CreateNoWindow = true
    }
};

process.Start();

Even though the NuGet Package SharpExifTool is based on your Tool, the problem lies there.
Just would have been nice to have my program not rely on an external tool to work.  :P