0

I've seen it asked here how to remove the Read-only attribute for a files and folders manually, but my question is a little different, and if it's been asked and answered, then I apologize. I did search first and didn't find anything.

Sometimes when I download a file or archive from the internet, it has the Read-only attribute set either on the file or archive itself, or on files and folders within the archive (probably set by the person who uploaded it). This can cause the program I use to access the file to throw an "access denied" error. I know how to clear the attribute manually using the attrib command, but I'd like to know if there's a way to remove the attribute automatically for all files when I download them, and/or when they are unpacked. If not, then could the following or a similar process be another way to achieve what I want (which is simply to not run into the error below, without having to manually remove the offending attribute case-by-case)?

(I'm the only user and my account is also the primary administrator, and "Owner" is already set to me) Downloads>Properties>Security>Advanced>check "Replace all child object permission entries with inheritable permission entries from this object">Apply>OK>OK

For context, I use an application that uses python scripts to automatically unpack a downloaded archive using 7zip, and move the files to another location on the same drive. This is all happening outside of Windows protected space (on my D:\ drive). The specific error being thrown is "[Winerror 5] Access is denied."

10
  • If you can alter your Python code, you can add some code to it it so that it removes the RO attribute. Please see the comments from Tim Roberts in this link → In Python the shutil.copy command makes the copy of the file read only - Stack Overflow
    – w32sh
    Sep 26, 2022 at 6:27
  • Thank you, but unfortunately that does not help me for a couple reasons. For starters, I'm not a programmer and I know nothing about Python. I just know that the program I'm using was written in Python, and from my initial research, I've gathered that particular error is specific to Python. Second, I know that the application/Python isn't setting the read-only attribute, merely passing it along, because the files that cause the error already have the attribute set when I download them, and files that don't already have the attribute don't result in an error. Sep 26, 2022 at 6:27
  • Ok. Do you know to which folder the archive is extracted? If the destination folder name is the same every time, I think there is a solution.
    – w32sh
    Sep 26, 2022 at 6:34
  • Yes, the location where the archive is extracted, as well as it's final destination, are both the same every time. The archive is initially downloaded and moved by me to a subfolder in Downloads, extracted by the application (using 7zip) to a subfolder in Documents, and then moved from there to a subfolder my Games folder, all on my D:\ drive. Sep 26, 2022 at 6:37
  • Do you mind downloading a tiny & portable folder watcher app ("NewFileGo") to resolve this issue? Shall post the instructions shortly.
    – w32sh
    Sep 26, 2022 at 6:38

1 Answer 1

1

You can accomplish this easily if you're willing to use portable third-party software such as NewFileGo.

  • Download NewFileGo and run it.
  • Click "Add New Watcher".
  • Type in the directory path you want to monitor.
  • Under "Command to Execute", select "run for each file"
  • Type attrib.exe -r "%s"
  • Click Save.

enter image description here

From now on, any new file created in the specified folder will have its Read-Only attribute removed automatically in real-time.

Optionally, you can add NewFileGo to your Startup folder so that it launches at login automatically.

I believe the same can be done using PowerShell FileSystemWatcher. But I'll have to test that on my systems before posting here.

1
  • Thank you very much. I'm going to check this out. I think what you've already posted is sufficient for my needs, but if you want to update it with the PowerShell solution, just for completeness sake or for others who might come across this in the future and prefer it, then be my guest. Marking this as the solution. Have a great rest of your night. Sep 26, 2022 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.