Error: Can not remove temporary directory

PIO was working OK. All of a sudden I got this error:
“Can not remove temporary directory C:\Users\smith\OneDrive\Documents\PlatformIO\Projects\Static Text\.pio\build.”
Deleted the file as directed.
Now I get same error when I try to compile any file I have tried.
Uninstalled and reinstalled VSC and PIO.
Updated all W10 drivers. Nothing seems to help. Anyone have an idea what I should try?
Thanks in advance.

Does this occur with projects outside OneDrive too?

I’m not ignoring you… I’m working on finding an answer.

I was referred from github to the forum to seek help with the same problem as described by the op.

My error:

Executing task: C:\Users\Radek\.platformio\penv\Scripts\platformio.exe run <

Can not remove temporary directory `D:\Documents\GitKraken\HELLO\.pio\build`. Please remove it manually to avoid build issues
Processing raspberry-pi-pico (platform: wizio-pico; board: raspberry-pi-pico; framework: baremetal)
Verbose mode can be enabled via `-v, --verbose` option
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'D:\\Documents\\GitKraken\\HELLO\\.pio':
  File "C:\Users\Radek\.platformio\penv\lib\site-packages\platformio\builder\", line 169:
  File "C:\Users\Radek\.platformio\python3\lib\", line 215:
    makedirs(head, exist_ok=exist_ok)
  File "C:\Users\Radek\.platformio\python3\lib\", line 215:
    makedirs(head, exist_ok=exist_ok)
  File "C:\Users\Radek\.platformio\python3\lib\", line 225:
    mkdir(name, mode)
========================================================== [FAILED] Took 0.53 seconds ==========================================================
The terminal process "C:\Users\Radek\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Thanks for moving this question to the forum. I think we have the same questions as @maxgerhardt asked above - does this project work if you move it to the C: drive?

Yes, it even works on D drive but it doesn’t when the PIO project folder is in one of my personal folders on D drive like: Documents, Downloads, Music, Pictures. I’ve been moving my folder to various locations and that’s what I have noticed.

Please provide an output of the pio system info command.

--------------------------  ------------------------------------------------------
PlatformIO Core             6.0.1b1
Python                      3.9.10-final.0
System Type                 windows_amd64
Platform                    Windows-10
File System Encoding        utf-8
Locale Encoding             cp1252
PlatformIO Core Directory   C:\Users\Radek\.platformio
PlatformIO Core Executable  C:\Users\Radek\.platformio\penv\Scripts\platformio.exe
Python Executable           C:\Users\Radek\.platformio\penv\Scripts\python.exe
Global Libraries            6
Development Platforms       4
Tools & Toolchains          21
--------------------------  ------------------------------------------------------

I moved the HELLO folder around:
D:\Documents1\Gitkraken\HELLO - builds
D:\Documents2\Gitkraken\HELLO - builds
D:\Documents\Gitkraken\HELLO - fails

All 3 folders have permissions inherited from D: I even refreshed the ownership and reapplied the inheritance to be sure. This is truly bizarre. The only difference is that Documents folder has an icon and is linked to Home Documents shortcut

Oh and first 2 folders successfully update include paths in c_cpp_properties.json whereas 3rd does not, have to update it manually.

What is the type of this path? I’m not a Windows user. I have a Windows virtual machine. What should I hack to reproduce the same as what you did?

It’s a normal path like other just being a target of the system link.

I’m sorry, the quality of embedded screenshots was degraded by the forum engine.
They look ok when you zoom the page though.

In the same CLI where pio --help works type


then in Python REPL

import os


Does this create a new folder by that path?

In Documents1-2 I can create the folder
In Documents I’m getting the following error:

>>> import os
>>> os.makedirs("D:/Documents/GitKraken/HELLO/.pio")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Radek\.platformio\python3\lib\", line 225, in makedirs
    mkdir(name, mode)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'D:/Documents/GitKraken/HELLO/.pio'

This is not a PlatformIO issue. Python can’t create a folder. I can’t help here because I’m not a Windows expert. Maybe other people can. Sorry.

OMG, I’ve figured this out. Windows 11 treats Python as a ransomware attack.
When I switched this off it started working again.

Microsoft is getting on my nerves recently.


Wow! Is this option enabled by default or do you turn it on manually? This is a big problem for PlatformIO :frowning:
PlatformIO is written in Python which is a scripting language. It means there are no signed binaries.

This option is on by default and all user folders are included permanently. You can add other folders, or disable it completely. What’s worse of all is that the system doesn’t even notify the user, or log that the process has been neutered from accessing the specific folder.


I’m just hoping it’s just a matter of time for Microsoft to whitelist the new pio python? eventually as one forum user speculated.

Any solution for this problem, beyond changing the MS Windows security settings? I can’t (and don’t want to) touch them, since they are disabled on my machine.