Как я могу узнать, на что указывает моя символическая ссылка?

Я использую что-то вроде этого для загрузки файла с URL:

if (!Directory.Exists(localFolder))
{
    Directory.CreateDirectory(localFolder);   
}


try
{
    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(Path.Combine(uri, filename));
    httpRequest.Method = "GET";

    // if the URI doesn't exist, an exception will be thrown here...
    using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
    {
        using (Stream responseStream = httpResponse.GetResponseStream())
        {
            using (FileStream localFileStream = 
                new FileStream(Path.Combine(localFolder, filename), FileMode.Create))
            {
                var buffer = new byte[4096];
                long totalBytesRead = 0;
                int bytesRead;

                while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    totalBytesRead += bytesRead;
                    localFileStream.Write(buffer, 0, bytesRead);
                }
            }
        }
    }
}
catch (Exception ex)
{
    // You might want to handle some specific errors : Just pass on up for now...
    // Remove this catch if you don't want to handle errors here.
    throw;
}
16
задан Strawberry 15 November 2010 в 06:03
поделиться

1 ответ

Если у вас есть утилита readlink(1) (часть GNU coreutils), она делает то, что вам нужно. В противном случае вы вроде как ручей, я не знаю ни одного простого & amp; переносной эквивалент.

25
ответ дан 30 November 2019 в 17:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: