title: The filename, directory name, or volume label syntax is incorrect: ':' Python
body: <p>I'am trying to add some new features to my file-management system. But I get struck with the following. I have 3 folders (Source, Destination and Archive). Each of them has 3 sub-folders (A, B and C). Only the sub-folders in Source contain 1 or more files. These will be re-written (moved) in Destination or Archive (depends on some requirements). </p>
  
  <p>The files in the sub-folders (A, B and C) in Source will only be rewritten to the sub-folders (A, B, and C) in Destination if:</p>
  
  <ol>
  <li>They <strong>ARE</strong> the last created file <strong>AND</strong> if they are at least 120 seconds old.</li>
  </ol>
  
  <p>If they <strong>ARE NOT</strong> the last created file but they <strong>ARE</strong> at least 120 seconds old, they will be moved to the sub-folders (A, B, and C) in Archive.</p>
  
  <p>If they <strong>ARE NOT</strong> the last created file and they <strong>ARE NOT</strong> at least 120 seconds old, they will stay in the current sub-folders (A, B, and C) in Source</p>
  
  <p>During the re-writing process, the content of Power in the file will be multiplied by 10. 
  [![which looks like this: <a href="https://i.stack.imgur.com/ee0r7.png" rel="nofollow noreferrer">https://i.stack.imgur.com/ee0r7.png</a> ] </p>
  
  <p>This is the code I have, I get the following error: <code>The filename, directory name, or volume label syntax is incorrect: ':'</code></p>
  
  <p>Can someone help and tell what I'm doing wrong and why nothing is getting re-written/moved or deleted? Much appreciated!</p>
  
  <pre><code>import os, os.path
  import time
  
  #Make source, destination and archive paths.
  src = r'c:\data\AM\Desktop\Source'
  dst = r'c:\data\AM\Desktop\Destination'
  arc = r'c:\data\AM\Desktop\Archive'
  
  os.chdir(src)
  
  #Now we want to get the absolute paths of the files which will be used to re-write the files.
  for root, subdirs, files in os.walk('.'):
      src_path = os.path.join(src, root)
      dst_path = os.path.join(dst, root)
      arc_path = os.path.join(arc, root)
  
  
      for f in files:
          src_fpath = os.path.join(src_path, f)
          dst_fpath = os.path.join(dst_path, f)
          arc_fpath = os.path.join(arc_path, f)
  
  #Get only the newest files inside the src_fpath and store it in newest_file_paths.
          newest_file_paths = max(src_fpath, key=os.path.getctime)
  
  
  #Now we start reading data from the old files, write it into the new files and delete the old files.        
          with open(src_fpath, 'r') as read1, open(dst_fpath, 'w') as write1, open(arc_fpath, 'w') as write2:
              data = {
                      'Power': None,
                      }
  
              for line in read1:
                  splitter = (ID, Item, Content, Status) = line.strip().split()
  #If the file(s) ARE the last created file(s) AND if they are at least 120 seconds old. Rewrite in Destination and remove in Source.
                  if read1 == newest_file_paths and os.path.getctime(newest_file_paths) &lt; time.time() - 120 and Item in data: 
                      Content = str(int(Content) * 10)
                      write1.write(ID+'\t'+Item+'\t'+Content+'\t'+Status+'\n') 
                      write1.write(line)
                      os.remove(src_fpath)
  #If the file(s)  ARE NOT the last created file(s) but they ARE at least 120 seconds old. Rewrite in Archive and remove in Source                   
                  elif read1 == newest_file_paths and os.path.getctime(newest_file_paths) &gt; time.time() - 120 and Item in data:
                      write2.write(line)
                      os.remove(src_fpath)
  #If they ARE NOT the last created file and they ARE NOT at least 120 seconds old. Stay in Source.                   
                  else:
                      continue
  </code></pre>