title: Read in command line arguments for folder paths and integer values
body: <p><strong>The goal of this program is to:</strong></p>
  <ol>
  <li>Take in 2 Folder paths</li>
  <li>Take in 1 Integer Value</li>
  <li>Validate both Folders are in the directory and that the Integer value is an int</li>
  <li>Move a specified number of files from the source folder into the destination folder. For example, if the source folder contains 8 files I want to move the last 4 files to the destination folder.</li>
  <li><strong>In Command line:</strong> python main.py path1 path2 4</li>
  </ol>
  <p>I'm in the testing phase of using Command line arguments instead of default value placeholders (Folder paths and integer values assigned to variables) and running through the console.</p>
  <p><strong>My issue is:</strong></p>
  <ol>
  <li>Everything work as intended when path1, path2, and int are all present and correct values</li>
  <li>If the integer is not an int (Example, python main.py path1 path2 <strong>string</strong>) the program crashes and gives me errors.</li>
  <li>If the program reads that the CLI arg is not an int (<strong>num = int(sys.argv[3])</strong>) I want to default the value to 10, but the program does not seem to do this?</li>
  </ol>
  <p><strong>ERROR</strong></p>
  <p>Blank = block out personal info<br />
  python main.py Path1 Path2 L</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\blank\blank\blank\main.py&quot;, line 71, in &lt;module&gt;
      main()
    File &quot;C:\Users\blank\blank\blank\main.py&quot;, line 66, in main
      read_args()
    File &quot;C:\Users\blank\blank\blank\main.py&quot;, line 29, in read_args
      num = int(sys.argv[3])
  ValueError: invalid literal for int() with base 10: 'L'
  </code></pre>
  <p><strong>Main</strong><br /></p>
  <pre><code>import os, sys, shutil, time
  
  def main():
      read_args()
  
  
  if __name__ == &quot;__main__&quot;:
      try:
          main()
      except KeyboardInterrupt:
          exit()
  </code></pre>
  <p><strong>Code</strong><br /></p>
  <pre><code>def validate_folder(folder):
      &quot;&quot;&quot;Validates folders in working directory&quot;&quot;&quot;
      try:
          isDir = os.path.isdir(folder)
          return isDir
      except Exception as e:
          print(e)
          return None
  
  def validate_number(number1):
      &quot;&quot;&quot;Validates third argument is an integer value&quot;&quot;&quot;
      try:
          int(number1)
          return True
      except ValueError:
          return False
  
  def read_args():
      &quot;&quot;&quot;Read CLI arguments&quot;&quot;&quot;
      source_folder = sys.argv[1]
      destination_folder = sys.argv[2]
      num = int(sys.argv[3])
  
      &quot;&quot;&quot;Get main folder and archive folder and validate they are in the directory&quot;&quot;&quot;
      main_folder = validate_folder(source_folder)
      archive_folder = validate_folder(destination_folder)
      kept_files = validate_number(num)
  
      &quot;&quot;&quot;If any of the inputs is not valid return None proceed with conditional checks&quot;&quot;&quot;
      if main_folder is False or archive_folder is False:
          print(&quot;Folders cannot be found&quot;)
      if main_folder is True and archive_folder is True and kept_files is False:
          num = 10
          sortFiles_and_moveFiles(source_folder, destination_folder, num)
      else:
          &quot;&quot;&quot;If both folders are valid in the working directory pass parameters to sortFiles_and_moveFiles()&quot;&quot;&quot;
          sortFiles_and_moveFiles(source_folder, destination_folder, num)
  
  
  def sortFiles_and_moveFiles(path1, path2, n_files):
      source_folder = path1
      destination_folder = path2
      &quot;&quot;&quot;Get list of all files only in the given directory&quot;&quot;&quot;
      list_of_files = filter(lambda x: os.path.isfile(os.path.join(source_folder, x)), os.listdir(source_folder))
  
      &quot;&quot;&quot;Sort list of files based on last modification time in descending order&quot;&quot;&quot;
      list_of_files = sorted(list_of_files, key=lambda x: os.path.getmtime(os.path.join(source_folder, x)))
  
      &quot;&quot;&quot;Iterate over sorted list of files and print file path, along with last modification time of file&quot;&quot;&quot;
      for file_name in list_of_files:
          file_path = os.path.join(source_folder, file_name)
          timestamp_str = time.strftime('%m/%d/%Y :: %H:%M:%S', time.gmtime(os.path.getmtime(file_path)))
          print(timestamp_str, ' --&gt;', file_name)
      print(&quot;Designated files have been moved&quot;)
      
      &quot;&quot;&quot;Move designated number of files to archive folder using slice notation.&quot;&quot;&quot;
      for file_name in list_of_files[n_files:]:
          shutil.move(os.path.join(source_folder, file_name), destination_folder)
  </code></pre>