title: (Python) 'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence & [Errno 22] Invalid argument:
body: <p>Get error this error <strong>&quot;'gbk' codec can't decode byte 0xb1 in position 5: illegal multibyte sequence&quot;</strong> ,when I try use this code :</p>
  <pre><code>        list_of_files2 = glob.glob('F:\\Project\\shiftly test\\Broadcom yield*.xls')  
          latest_file2 = max(list_of_files2, key=os.path.getmtime)
  </code></pre>
  <p>While change to this code , get this error  <strong>[Errno 22] Invalid argument: &quot;b'F:\\\\Project\\\\shiftly test\\Broadcom yield_2022-03-30.xls'&quot;</strong></p>
  <pre><code>            list_of_files2 = glob.glob(rb'F:\\Project\\shiftly test\\Broadcom yield*.xls')  
             latest_file2 = max(list_of_files2, key=os.path.getmtime)
  </code></pre>
  <p>It seem like unable decoding the file properly .</p>
  <p>Here the full code</p>
  <pre><code>if __name__ == &quot;__main__&quot;:
  # while (True):
  # for DIR in [DB_DIR]:
  # if os.listdir(DIR) != []:
  if os.path.exists(DB_DIR) != []:
      xmlfiles = os.listdir(DB_DIR)
  
      # Copy xls.file to another path
      list_of_files = glob.glob('F:\\Project\\shiftly test\\Broadcom yield*.xls')
      latest_file = max(list_of_files, key=os.path.getmtime)
  
  
      print
      &quot;latest %s&quot; % (latest_file)
  
      with open('F:\\Project\\no_duplicate\\no_duplicate.txt','r') as myfile:
          data = myfile.read()
  
          print
          &quot;read line %s&quot; % (data)
  
      if latest_file != data:
  
          list_of_files2 = glob.glob(rb'F:\\Project\\shiftly test\\Broadcom yield*.xls')  ########################################## need change later
          latest_file2 = max(list_of_files2, key=os.path.getmtime)
  
          # time.sleep(10)
  
          try:
              statinfo = os.stat(latest_file2)
  
          except Exception as e :
              print (e)
  
          try:
              extratwword(latest_file2)
              with open('F:\\Project\\no_duplicate\\no_duplicate.txt','r+') as f:
                  # convert to string:
                  data = f.read()
                  print
                  &quot;Done -- Writing &amp; Executing: %s &quot; % (data)
                  f.seek(0)
                  f.write(latest_file)
                  f.truncate()
  
          except Exception as e:
              print (e)
  </code></pre>