【问题标题】:IDL- Creating an array of mtimes of all of the files in a directoryIDL-创建目录中所有文件的 mtimes 数组
【发布时间】:2015-11-04 05:11:00
【问题描述】:

所以我正在尝试创建一个程序来搜索目录中最近更新的文件。 我最初的希望是像

这样的命令
file_array = FILE_INFO(file_path+'\*.dat')

将创建一个包含目录中所有文件的数组,然后

edit_time = file_array.mtime

会给我一个包含所有 mtime 的数组,从中我可以获得最大 mtime,也就是最近更新的文件。不过,据我所知,FILE_INFO(和FSTAT)似乎无法同时处理多个文件。

这个程序应该是一个自动化程序,随着数据被推送到计算机上,文件会不断更新和添加。因此,在比父目录更具体的内容中进行硬编码并不是一个可行的解决方案。

所以我需要一个可以处理多个文件的FILE_INFO 的替代方法,或者一个可以单步执行目录的循环过程,查看每个文件,而无需先知道文件名。

【问题讨论】:

    标签: arrays loops automation idl filemtime


    【解决方案1】:

    这样的事情怎么样:

    function mg_newest_file, dirname, _extra=e
      compile_opt strictarr
    
      files = file_search(filepath('*', root=dirname), count=nfiles, _extra=e)
      info = replicate(file_info(files[0]), nfiles)
      for i = 0L, nfiles - 1L do begin
        info[i] = file_info(files[i])
      endfor
    
      ind = sort(info.mtime)
      return, files[ind[-1]]
    end
    

    这样调用它以在给定目录中查找最新的常规文件:

    IDL> print, mg_newest_file('/Users/mgalloy/projects/mglib', /test_regular)
    /Users/mgalloy/projects/mglib/homebrew_configure.sh
    

    根据您的工作,FOLDERWATCH(在 IDL 8.4 中引入)可能对您有用。

    【讨论】:

    • 由于我们拥有许可,我只能使用 8.2,因此无法使用文件夹监视。不过,我会尝试您的解决方案并回复您。
    猜你喜欢
    • 2014-03-07
    • 2013-06-21
    • 2012-12-31
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多