title: Permission denied [Errno13] on Windows 10
body: <p>Unfortunately I can't figure out why this error occurs. Tried also to set <code>os.chmod</code> to 0o777 and make dir to <code>os.chdir(dir)</code> but the error still remains. Hope you can help me out.</p>
  
  <pre><code>#!/usr/bin/env python 
  '''This version of the readserial program demonstrates using python to write an output file'''
  from datetime import datetime 
  from datetime import date
  import serial, io
  import socket
  import os
  TCP_IP = 'localhost'
  TCP_PORT = 23
  BUFFER_SIZE = 1024
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((TCP_IP, TCP_PORT))
  recordNr = 0
  firstLine = "Time\tMagnetometer Values [uT]\t\t\tAccelerometer Values[m/s2]"
  secondLine = "\txAxis\tyAxis\tzAxis\txAxis\tyAxis\tzAxis"
  #outfile='C:/Users/ebhproduser/Desktop/serial.csv'
  ser = serial.Serial(port='COM5', baudrate=9600)
  sio = io.TextIOWrapper(
      io.BufferedRWPair(ser, ser, 1),
      encoding='ascii', newline='\r' 
      )
  
  while ser.isOpen(): 
          today = str(date.today())
          datastring = sio.readline()
          try:
              data = [abs(float(x)) for x in datastring.split(';')]
          except ValueError:
              continue
  
          dir = r'C:/Users/ebhproduser/Desktop/'+today + '/'
          filename = 'record-' + str(recordNr) +'.csv'
          outfile = dir+filename  
          if not os.path.exists(dir):
              os.makedirs(dir, os.umask(0o777))
              os.chdir(dir)
          #os.chmod(outfile,0o777)
          if (data[2] &lt; 1000):
              with open(outfile,'a+') as f: #appends to existing file and '+' bedeutet, dass das File erstellt wird, falls nicht existent   
                  MESSAGE = datetime.utcnow().isoformat()
                  #\t is tab; \n is line separator
                  f.write(datetime.utcnow().isoformat() + '\t' + datastring + '\n')
                  f.flush() #included to force the system to write to disk
                  s.send(MESSAGE.encode())
                  f.close()
          else:
              f.close()
              recordNr = +1
  ser.close()
  </code></pre>
  
  <p>Error is:</p>
  
  <pre><code> Traceback (most recent call last):
    File "C:\Users\ebhproduser\Desktop\new1.py", line 38, in &lt;module&gt;
      with open(outfile,'a+') as f: #appends to existing file and '+' bedeutet, dass das File erstellt wird, falls nicht existent
  PermissionError: [Errno 13] Permission denied: 'C:/Users/ebhproduser/Desktop/2018-03-14/record-0.csv'
  </code></pre>
  
  <p>UPDATE: The thing about the error must be something dealing with write permissions to created folder. As <code>os.chmod</code> not (fully) works on WINDOWS. So if somebody facing the same issue I recommend to read <a href="https://stackoverflow.com/questions/12168110/setting-folder-permissions-in-windows-using-python">this one</a> and <a href="http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html" rel="nofollow noreferrer">this one</a>.</p>