文件夹拷贝,保留文件修改时间, 按修改时间最新排序
2011-08-09 19:36
330 查看
import sys, os, time, shutil
from stat import ST_ATIME, ST_CTIME, ST_MTIME
from win32file import CopyFile
def test(self):
remoteDir = "\\\\orc-fs\\Builds\\FP\\builds01\\flair\\Main"
localDir = "d:\\Main"
i = 0
for name in os.listdir(remoteDir):
print name
if i == 3:
break
shutil.copytree(os.path.join(remoteDir, name), os.path.join(localDir, name), True)
try:
stat1 = os.stat(os.path.join(remoteDir, name))
print stat1
print time.ctime(stat1[ST_CTIME]), time.ctime(stat1[ST_MTIME])
except os.error:
sys.stderr.write("Error")
sys.exit(1)
try:
os.utime(os.path.join(localDir, name), (stat1[ST_CTIME], stat1[ST_MTIME]))
stat2 = os.stat(os.path.join(localDir, name))
os.path.getctime(os.path.join(localDir, name))
print time.ctime(stat2[ST_CTIME]), time.ctime(stat2[ST_MTIME])
except os.error:
sys.stderr.write("Error")
sys.exit(2)
if stat1[ST_CTIME] == stat2[ST_CTIME] and stat1[ST_MTIME] == stat2[ST_MTIME]:
print "Good"
i += 1
def compare(self):
remoteDir = "\\\\orc-fs\\Builds\\FP\\builds01\\flair\\Main"
localDir = "d:\\Main"
files = [(os.path.getmtime(os.path.join(remoteDir, x)) , os.path.join(remoteDir, x)) for x in os.listdir(remoteDir)]
files.sort()
files.reverse()
for item in files:
print item
if __name__ == "__main__":
# test(1)
compare(1)
from stat import ST_ATIME, ST_CTIME, ST_MTIME
from win32file import CopyFile
def test(self):
remoteDir = "\\\\orc-fs\\Builds\\FP\\builds01\\flair\\Main"
localDir = "d:\\Main"
i = 0
for name in os.listdir(remoteDir):
print name
if i == 3:
break
shutil.copytree(os.path.join(remoteDir, name), os.path.join(localDir, name), True)
try:
stat1 = os.stat(os.path.join(remoteDir, name))
print stat1
print time.ctime(stat1[ST_CTIME]), time.ctime(stat1[ST_MTIME])
except os.error:
sys.stderr.write("Error")
sys.exit(1)
try:
os.utime(os.path.join(localDir, name), (stat1[ST_CTIME], stat1[ST_MTIME]))
stat2 = os.stat(os.path.join(localDir, name))
os.path.getctime(os.path.join(localDir, name))
print time.ctime(stat2[ST_CTIME]), time.ctime(stat2[ST_MTIME])
except os.error:
sys.stderr.write("Error")
sys.exit(2)
if stat1[ST_CTIME] == stat2[ST_CTIME] and stat1[ST_MTIME] == stat2[ST_MTIME]:
print "Good"
i += 1
def compare(self):
remoteDir = "\\\\orc-fs\\Builds\\FP\\builds01\\flair\\Main"
localDir = "d:\\Main"
files = [(os.path.getmtime(os.path.join(remoteDir, x)) , os.path.join(remoteDir, x)) for x in os.listdir(remoteDir)]
files.sort()
files.reverse()
for item in files:
print item
if __name__ == "__main__":
# test(1)
compare(1)
相关文章推荐
- linux如何看一个文件夹内(包括子文件夹内)n天内修改了的文件,并且按修改时间排序(最下方是最新的)
- java实现按照文件的修改时间排序文件夹下的文件
- 把文件夹下的文件按修改时间先后顺序排序
- 文件夹下所有文件按修改时间 排序
- 文件夹中文件夹(文件)按时间排序,读取最新的文件夹(文件)
- 文件夹中文件夹(文件)按时间排序,读取最新的文件夹(文件)
- ASP 按修改时间读取文件夹中文件并且排序
- C#实现对指定文件夹中文件按修改时间排序
- C#实现对指定文件夹中文件按修改时间排序
- 文件夹中文件夹(文件)按时间排序,读取最新的文件夹(文件)
- C#实现对指定文件夹中文件按修改时间排序
- C#文件和文件文件夹按时间、名称排序-顺序与倒序
- android同一文件夹的文件按时间、文件大小、名称排序
- linux 中使用ls命令对文件进行排序-- 基于文件大小或者修改时间
- 关于os模块中的文件夹遍历,文件操作,文件的创建和修改时间的用法
- 按照文件修改时间遍历文件夹,进行文本连接
- iOS 通过文件的修改时间遍历整个文件夹
- [BAT] 以当前时间为名创建文件夹,将本地文件夹里的文件拷贝到远程共享目录
- 自动更新文件夹下所有DLL 至最新修改时间版本
- 对获取的文件根据修改的时间进行排序