Is file is readable windows

First off: I know that this isn’t reliable for actually checking if I can write. I’m writing a file transfer client, and want feature parity between the «remote» and «local» file browser panes. I fully understand I will have to handle any permission related exceptions for any operation performed regardless; it’s not a programming check it’s just to display to the user.

I’ve seen several examples for these posted, but everything I’ve tried either wasn’t understandable or didn’t work. I’ve tried the following two methods, but both just returned «yes» for things I definitely can’t write to (the contents of C:\Windows or C:\Program Files, for example):

System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, Path);
return System.Security.SecurityManager.IsGranted(fp);

and

System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, element.Path);
try
{
    fp.Assert();
    return true;
}
catch(Exception x)
{
    return false;
}

(Again, I’m aware that both catching Exception is horrible and using try/catch for logic is slightly less horrible, I’m just trying to get this to work).

The first one tells me that IsGranted is deprecated and I should be using AppDomain.PermissionSet or Application.PermissionSet, but I can’t find any explanation of how to use these that makes sense. I’ve also seen that I should be manually enumerating all the ACLs to figure it out myself, but again there’s no real examples of this. There’s quite a few examples for setting permissions, but few for checking them.

Any help would be greatly appreciated.

First off: I know that this isn’t reliable for actually checking if I can write. I’m writing a file transfer client, and want feature parity between the «remote» and «local» file browser panes. I fully understand I will have to handle any permission related exceptions for any operation performed regardless; it’s not a programming check it’s just to display to the user.

I’ve seen several examples for these posted, but everything I’ve tried either wasn’t understandable or didn’t work. I’ve tried the following two methods, but both just returned «yes» for things I definitely can’t write to (the contents of C:\Windows or C:\Program Files, for example):

System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, Path);
return System.Security.SecurityManager.IsGranted(fp);

and

System.Security.Permissions.FileIOPermission fp = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, element.Path);
try
{
    fp.Assert();
    return true;
}
catch(Exception x)
{
    return false;
}

(Again, I’m aware that both catching Exception is horrible and using try/catch for logic is slightly less horrible, I’m just trying to get this to work).

The first one tells me that IsGranted is deprecated and I should be using AppDomain.PermissionSet or Application.PermissionSet, but I can’t find any explanation of how to use these that makes sense. I’ve also seen that I should be manually enumerating all the ACLs to figure it out myself, but again there’s no real examples of this. There’s quite a few examples for setting permissions, but few for checking them.

Any help would be greatly appreciated.

Question: is there a (built-in?) way in Windows to fully read 100% of
the bytes of every file on a volume, to make sure that every file is
really readable without any I/O error?

Answer:

/r Locates bad sectors and recovers readable information. The disk must be locked. /r includes the functionality of /f, with the additional analysis of physical disk errors.

enter image description here

Remarks:

Of course, the smallest addressable unit on a drive being a sector, and the smallest addressable unit on a volume being a cluster, chkdsk does not check individual bytes.

IOW chkdsk will attempt to determine the readability of a cluster and in case of read issues will try to recover the data within an entire cluster.

At the drive level errors are determined by the readability of a sector. IOW the drive is able to read the sector that is a requested (even if after error recovery at firmware level) or it is not. If the latter the drive returns an error indicating the sector can not be read and no data is returned for the sector (so either 512 bytes or 4 KB worth of data).

While you’re talking about files, eventually this is the level it comes down to. IOW it’s not about individual bytes being checked.

Since chkdsk checks all ‘sectors’ within volume, no errors means that all files are readable.

Every once in a while you have to work with files. This article will teach you how to check wheter or not file is readable or writeable. You’re also going to learn how to check if given file or directory exists.

Quick intro to C# File, FileInfo, Directory and DirectoryInfo classes

All four classes reside inside System.IO namespace. It’s important to notice the differences between those clasesses, especially in terms of not-Info and Info classes.

The File class is used to manipulate files. You can use it to create, write to and delete a file. You can also get file attributes. It’s a static class without constructor, so you have to pass a path to a file in each method call.

The FileInfo is used to manipulate files, so you can create, write to and delete a file. This class however is not static, you have to create instance of it and you pass a path to file in constructor.

The difference between Directory and DirectoryInfo is basically the same as the difference between File and FileInfo. Former is a static class used to operate on directories and latter requires you to create instance for each path.

Check if file exists

1
var exists = System.IO.File.Exists(@"c:\file.txt");
1
2
var fileInfo = new System.IO.FileInfo(@"c:\file.txt");
var exists = fileInfo.Exists;

Check if directory exists

1
var exists = System.IO.Directory.Exists(@"d:\directory");
1
2
var directoryInfo = new System.IO.DirectoryInfo(@"d:\directory");
var exists = directoryInfo.Exists;

Test if path is a file or directory

One way to do it is to check wheter or not file/directory exists. It comes with a drawback however, because it won’t tell you explicitly if the path is a file/directory or if it simply doesn’t exist. In order to make sure that the tested path is directory (or file) and it exists we need to test it both ways. I have wrapped it all together into single method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public enum PathType { NonExisting = 0, File = 1, Directory = 2 };

public PathType GetPathType(string path)
{
    if (File.Exists(path))
    {
        return PathType.File;
    }

    if (Directory.Exists(path))
    {
        return PathType.Directory;
    }

    return PathType.NonExisting;
}

var pathType = GetPathType(@"c:\Windows");

The second method which we can use is to get path file/directory attributes. Note that when file or directory does not exists it will throw System.IO.FileNotFoundException:

1
2
3
var attributes = File.GetAttributes(path);
var isFile = !attributes.HasFlag(FileAttributes.Directory);
var isDirectory = attributes.HasFlag(FileAttributes.Directory);

It’s also worth noting that file attributes are also exposed via FileInfo.Attributes property:

1
var attributes = new System.IO.FileInfo(@"c:\file.txt").Attributes;

Verify if file is read-only

It’s pretty easy to check read-only file flag using attributes:

1
var isReadonly = new System.IO.FileInfo(@"C:\file.txt").Attributes.HasFlag(System.IO.FileAttributes.ReadOnly);

Check if file is readable or writeable

Wheter a file can be read or not depends on multiple factors. The following example is simplified, but you should take into account that:

  • file may not exists
  • file could be locked by some other process
  • someone/something can change access to a file during execution of your applications
  • you may not have proper permissions (file may belong to other user)
  • in case of errors it will throw exceptions
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
using (var fs = new FileStream(@"C:\file.txt", FileMode.Open))
{
    var canRead = fs.CanRead;
    var canWrite = fs.CanWrite;
}

// File.Open also returns FileStream
// there are also two "shortcut" methods: File.OpenRead, File.OpenWrite
using (var fs = File.Open(@"C:\file.txt", FileMode.Open))
{
    var canRead = fs.CanRead;
    var canWrite = fs.CanWrite;
}

Also FileStream is disposeable so remember to disposed it afterwards, in this case we’re using the using statement.

Author
Zbigniew

LastMod
2019-04-28

Windows 10: my file is not readable. how do I change it so I can read it?

Discus and support my file is not readable. how do I change it so I can read it? in Windows 10 Software and Apps to solve the problem; my file is not readable. how do I change it so I can read it?…
Discussion in ‘Windows 10 Software and Apps’ started by JuneShipley, Aug 20, 2018.

  1. my file is not readable. how do I change it so I can read it?

    my file is not readable. how do I change it so I can read it?

    :)

  2. unable to read 3D xray discs that have been readable in past.

    Hi,

    There are a lot of possible causes why the error occurred. To isolate this matter, we have some questions for you:

    • Were there any changes made before the issue occurred?
    • How do you open the DVD file?
    • Have you tried inserting the DVD disc to another computer?
    • What are the troubleshooting steps have you done so far?

    We suggest that perform these troubleshooting steps:

    Update your drivers.

    To know how to update your drivers, click
    here.

    Run Hardware and Devices Troubleshooter.

    To run the
    Troubleshooter, follow these steps:

    • On the search bar, type
      Troubleshooting
      and hit
      Enter.
    • Choose
      Hardware and Sound.
    • Click
      on Hardware and Devices
      to run the
      troubleshooter.

    Update us on how it goes.

    Regards.

  3. Edge Search Does Not Permit Change of Region

    I got these suggestions from the Microsoft Community forum.No. 1 worked for me:

    Thank you for posting the query on Microsoft Community. I am glad to assist you on this.
    We have reproduce the issue here and we are able to access non-regional search for google using Microsoft Edge.
    I would suggest you to try the below steps and check if it helps.
    Step 1:
    Clear browsing data option of Microsoft Edge and check if you face the issue. To do so perform the steps below.

    • Click on the More actions icon next to the feedback icon present on top right corner of the Project Spartan homepage.
    • Select Settings and click on Choose what to clear.
    • Check the boxes Browsing history, Cookies and saved website data and Cached data and files and click on Clear.

    Step 2:
    I suggest you to create a new user account and check if the issue occurs.

    • Go to Settings.
    • Choose Accounts and then select Family and other users.
    • Select add someone else on this PC.
    • Enter a user name and hit next.
    • Click on Finish.
    • Sign out from the current Account and Log into the new account.

    Step 3:
    It could also happen because of network issue. I suggest you to try with different network connection and check if it helps.

  4. my file is not readable. how do I change it so I can read it?

    Overclocking / Undervolting guide for Vega 56 or 64?

    Here’s a quick laundry list:

    List of software to use for overclocking and testing
    Examples:
    Wattman (and how to find and use it, like an overview, including profiles)
    Unigine Valley or Heaven (use this for quick testing while changing settings in Wattman and checking for stability / artifacts) …just suggesting this
    How to monitor cores / mem speeds and temps during testing (I’ve seen screen overlays, and others using GPUz)

    Step-by step overclocking in Wattman
    Fan speeds
    Power limit
    Temp limit
    Voltages
    Core speeds
    Memory speeds

Thema:

my file is not readable. how do I change it so I can read it?

  1. my file is not readable. how do I change it so I can read it? — Similar Threads — file readable change

  2. How do I change an attribute WITHIN the metadata so that it is no longer read only?

    in Windows 10 Network and Sharing

    How do I change an attribute WITHIN the metadata so that it is no longer read only?: Situation: I have some .mp4 files that shows me the wrong title when playing within a player such as Windows Media Player. Inside the file properties menu there is a «detail» pane that has a «title» field which originally contained a title that is different than the file name…
  3. How do I change an attribute WITHIN the metadata so that it is no longer read only?

    in Windows 10 Gaming

    How do I change an attribute WITHIN the metadata so that it is no longer read only?: Situation: I have some .mp4 files that shows me the wrong title when playing within a player such as Windows Media Player. Inside the file properties menu there is a «detail» pane that has a «title» field which originally contained a title that is different than the file name…
  4. How do I change an attribute WITHIN the metadata so that it is no longer read only?

    in Windows 10 Software and Apps

    How do I change an attribute WITHIN the metadata so that it is no longer read only?: Situation: I have some .mp4 files that shows me the wrong title when playing within a player such as Windows Media Player. Inside the file properties menu there is a «detail» pane that has a «title» field which originally contained a title that is different than the file name…
  5. How do I change Adobe so it’s not my default for Pdf files?

    in Windows 10 Gaming

    How do I change Adobe so it’s not my default for Pdf files?: How do I change Adobe so it’s not my default for Pdf files?

    https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-change-adobe-so-its-not-my-default-for/20e1d6a4-6caa-465a-97b3-cb98f750c671

  6. How do I change Adobe so it’s not my default for Pdf files?

    in Windows 10 Software and Apps

    How do I change Adobe so it’s not my default for Pdf files?: How do I change Adobe so it’s not my default for Pdf files?

    https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-change-adobe-so-its-not-my-default-for/20e1d6a4-6caa-465a-97b3-cb98f750c671

  7. How do I read my clipboard?

    in Windows 10 Gaming

    How do I read my clipboard?: how do I read my clipboard?

    https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-read-my-clipboard/079e330f-41df-4edd-a736-5500266add17

  8. How do I read my clipboard?

    in Windows 10 Software and Apps

    How do I read my clipboard?: how do I read my clipboard?

    https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-read-my-clipboard/079e330f-41df-4edd-a736-5500266add17

  9. how do i unlock a file or folder so i can move it

    in Windows 10 Support

    how do i unlock a file or folder so i can move it: Howdy,

    i often cannot move a folder to another location because windows says it’s currently in use in another program. i checked and closed all programs. still the same error.

    i downloaded a cool program named «Lockhunter — a foolproof file unlocker». It sits in the…

  10. How do I read/analyze this dump file so I know what is causing the BSO

    in Windows 10 BSOD Crashes and Debugging

    How do I read/analyze this dump file so I know what is causing the BSO: I built a pc last week and I get the BSOD after a few minutes of playing any game I try. I only have the last dump file I got because the BSOD before the last wouldn’t let me start my pc in safe mode or restore to a previous date so I had to reinstall windows 10. Here is my…

Users found this page by searching for:

  1. file is not readable

    ,

  2. .info file is not readable

    ,

  3. my exml file is not readable


Windows 10 Forums

  • Irst драйвер для установки windows 10 скачать
  • Iso windows server 2012 r2 download
  • Iso образ windows 11 что это
  • Iso windows 10 64 bit скачать для rufus
  • Iso образ windows 10 для флешки rufus