Skip to main content
Code Review

Return to Question

Post Reopened by 301_Moved_Permanently, Heslacher, Graipher, Community Bot, Tunaki
Remove off-topic, obsolete part of question.
Source Link
user34073
user34073

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

Actually I might have an answer for this, but if you still feel it's the wrong way please let me know.

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

This is what I've got and it seems to be right in that they're comparing the same attributes. If If there is a better, more pythonicPythonic way for this, please advise :).

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

Actually I might have an answer for this, but if you still feel it's the wrong way please let me know.

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

This is what I've got and it seems to be right in that they're comparing the same attributes. If there is a better more pythonic way for this please advise :)

I am attempting to find folders based on their last modified dates.

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

This is what I've got and it seems to be right in that they're comparing the same attributes. If there is a better, more Pythonic way for this, please advise.

added 760 characters in body
Source Link
janos
  • 112.9k
  • 15
  • 154
  • 396

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

Actually I might have an answer for this, but if you still feel it's the wrong way please let me know.

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

This is what I've got and it seems to be right in that they're comparing the same attributes. If there is a better more pythonic way for this please advise :)

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

Actually I might have an answer for this, but if you still feel it's the wrong way please let me know.

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))
 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

This is what I've got and it seems to be right in that they're comparing the same attributes. If there is a better more pythonic way for this please advise :)

added 224 characters in body
Source Link

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Folder"\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 ifmodifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name))) > 2016 strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/11%m/20%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time
srcFolders = "C:\Users\Test\Desktop\Folder"
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 if time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name))) > 2016/11/20:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

I am attempting to find folders based on their last modified dates. I can get the dates and folders (or directory names) but I'm unsure as to the best way to check that they are before a certain date.

So far I have:

import os, shutil, stat, errno, time, datetime
srcFolders = "C:\Users\Test\Desktop\Test"
archiveDate = datetime.datetime.strptime("2016年11月20日", '%Y/%m/%d')
os.chdir(srcFolders)
for name in os.listdir('.'):
 if os.path.isdir(name):
 modifiedDate = time.strftime('%Y/%m/%d', time.gmtime(os.path.getmtime(name)))  strLastModified = datetime.datetime.strptime(modifiedDate, '%Y/%m/%d')
 if strLastModified > archiveDate:
 print name

However this doesn't feel like it's right, as I don't think I'm comparing them correctly. Could someone advise if I'm going about this the right way?

Post Closed as "Not suitable for this site" by Graipher, 200_success
added 12 characters in body
Source Link
Grajdeanu Alex
  • 9.3k
  • 4
  • 32
  • 71
Loading
Source Link
CFNZ_Techie
  • 305
  • 2
  • 11
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /