How to delete unreachable files from windows TEMPORARY folder with a C#application

Asked

Viewed 86 times

0

insert image description here

I’m trying to create a C# application to delete files and subfolders from the windows directory where the temp folder is located (C: Users Admin Appdata Local Temp), where I can perform with any other folder but only this not due to having files which I could not find or delete. I would like to know please how to get around this error and thus manage to delete the other files I have in this folder in case some are not found. I don’t know where else to look or any article to help me. Thank you very much.inserir a descrição da imagem aqui insert image description here

  • Try to open Visual Studio as Administrator. Right-click on the VS shortcut and "Run as Administrator".

  • It is a temporary file that must be in use by some application or by the system.

  • I understand, but I want to skip this file and continue. To pass to the next ones, because the error appears and only for there and not of the continuity. It has more files and the error appears and is not treated to continue. and what I’m needing, to continue treating or ignoring the file error being used.

  • @Josimarmarcos put the file deletion inside a block try and within an exception handler of a continue. PS: I’m not going to answer that question because the code was attached as an image. Read The No Questions Manual | Do not publish code as image

  • Ricardo for the tip and guidance, had not attacked me for way of use. I thank from now.

2 answers

1

As you want to skip the file and continue, put the instruction inside a Try.. catch block:

try {
    fi.Delete();
} catch { }

0

I believe you need to open the application as an administrator, so do the following steps:

  • Click Project - Add New Item - select Manifest File (Windows only)

Then a manifest file will be generated in your project, whose name is app.manifest.

  • Now, get into your manifest file and look for the written line <requestedExecutionLevel level="asInvoker" uiAccess="false" /> and change the asInvoker for requireAdministrator

Thus remaining: <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Now, click on Iniciar for Visual Studio to restart it and open with more privileges, running your application as Administrator.

Now run the tests. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.