I know ... I know... you can do that in Window's Explorer ...
find stuff ... sort stuff ... check modification date ...
but nothing is nicer than having a hardcopy in your hand to document where things are at a point in time.
To this end, I began poking around in the os module and the arcpy.da module looking at the options for traversing paths. This lead me to some amazing threads on GeoNet and elsewhere about documenting data sources and types. Many people went to great lengths to develop the Amazing-o-rama that would document everything ... everywhere and at any time.
Me? I know where all my data are.
My needs are simple...I have a couple of folders of shapefiles, a couple of folders of grids, some *.tif and *.sid things and more recently...from cajoling by some nameless cohorts on this forum...a real file geodatabase.
I generally don't make maps, I generally don't need real world data and when it comes to most things, a geometry type is a geometry type, maybe with its own personality, but the same-ish is good enough.
What I really need to do is find simple things. Python scripts...text files...*.png images for manuals, *.wpd (yes WordPerfect) and the odd *.doc/docx file.
This led me to the distraction ... simply explore the os module, specifically os.walk which of course led me to arcpy.da.walk and somewhere along the path...the time and datetime modules. I got sidetracked into Python's Mini Formatting Language, the collections module (again!) and base python object properties and how some properties are not as overtly exposed as others. The later one, will be the focus of my next post.
So for now...here is my documentation and the script that meets my simple needs.
In the if __name__ == '__main__': section, you can change the source folder, the file extension you are looking for. All other 'crap'...whether you want to get creation/modification/some-other-time option have been stripped back.
I have written in a style as noted in the script header. I could turn it into a toolbox tool...but why...I have emailed it to myself...could use "the cloud", but that sounds pretentious and downright '60's.
<SPAN class="string token">""</SPAN>"
Script<SPAN class="punctuation token">:</SPAN> files_in_path<SPAN class="punctuation token">.</SPAN>py
Path<SPAN class="punctuation token">:</SPAN> F<SPAN class="punctuation token">:</SPAN>\A0_Main\
Author<SPAN class="punctuation token">:</SPAN> Dan<SPAN class="punctuation token">.</SPAN>Patterson@carleton<SPAN class="punctuation token">.</SPAN>ca
Created<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">2015</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">05</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">25</SPAN>
Modified<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">2015</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">05</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">25</SPAN> <SPAN class="punctuation token">(</SPAN>last change date<SPAN class="punctuation token">)</SPAN>
Purpose<SPAN class="punctuation token">:</SPAN> To find all scripts <SPAN class="keyword token">with</SPAN> an <SPAN class="string token">'ending'</SPAN> <SPAN class="keyword token">in</SPAN> a path
Notes<SPAN class="punctuation token">:</SPAN>
As verbose <SPAN class="keyword token">as</SPAN> possible<SPAN class="punctuation token">.</SPAN> No error checking <SPAN class="keyword token">is</SPAN> intentional<SPAN class="punctuation token">,</SPAN> to minimize
bloat to permit verbosity <SPAN class="punctuation token">(</SPAN>If you follow that<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>good<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>
References<SPAN class="punctuation token">:</SPAN>
Size <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
PEP <SPAN class="number token">8</SPAN><SPAN class="punctuation token">:</SPAN> "For sequences<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>strings<SPAN class="punctuation token">,</SPAN> lists<SPAN class="punctuation token">,</SPAN> tuples<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> use the fact that empty
sequences are false<SPAN class="punctuation token">.</SPAN>"
<SPAN class="operator token">-</SPAN> this applies to any sequence that has a len<SPAN class="punctuation token">,</SPAN> __len__ method<SPAN class="punctuation token">,</SPAN> such <SPAN class="keyword token">as</SPAN>
collections<SPAN class="punctuation token">.</SPAN>Counter<SPAN class="punctuation token">,</SPAN> collections<SPAN class="punctuation token">.</SPAN>OrderedDict etc
<SPAN class="operator token">-</SPAN> see empty_tests<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">for</SPAN> more discussion
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> objs <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"one"</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"1"</SPAN><SPAN class="punctuation token">,</SPAN>None<SPAN class="punctuation token">,</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> is_empty <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="operator token">not</SPAN> i <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> objs <SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># not used, but useful</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">print</SPAN> is_empty <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
<SPAN class="operator token">-</SPAN>
<SPAN class="operator token">-</SPAN> <SPAN class="keyword token">for</SPAN> NumPy arrays use size<SPAN class="punctuation token">:</SPAN>
x <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN><SPAN class="operator token">></SPAN> len<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> x<SPAN class="punctuation token">.</SPAN>size <SPAN class="operator token">==</SPAN> <SPAN class="number token">0</SPAN>
Time <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
http<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">//</SPAN>stackoverflow<SPAN class="punctuation token">.</SPAN>com<SPAN class="operator token">/</SPAN>questions<SPAN class="operator token">/</SPAN><SPAN class="number token">237079</SPAN><SPAN class="operator token">/</SPAN>
http<SPAN class="punctuation token">:</SPAN><SPAN class="operator token">//</SPAN>gis<SPAN class="punctuation token">.</SPAN>stackexchange<SPAN class="punctuation token">.</SPAN>com<SPAN class="operator token">/</SPAN>questions<SPAN class="operator token">/</SPAN><SPAN class="number token">48537</SPAN><SPAN class="operator token">/</SPAN>how<SPAN class="operator token">-</SPAN>to<SPAN class="operator token">-</SPAN>make<SPAN class="operator token">-</SPAN>a<SPAN class="operator token">-</SPAN>gis<SPAN class="operator token">-</SPAN>inventory
<SPAN class="string token">"""
import sys
import os
import datetime
def mod_time(folder,case):
"""</SPAN>obtain the modified time <SPAN class="keyword token">for</SPAN> the file <SPAN class="operator token">and</SPAN> path
get the file name<SPAN class="punctuation token">,</SPAN> the modification time<SPAN class="punctuation token">,</SPAN>
convert to readable time<SPAN class="punctuation token">,</SPAN> then format
<SPAN class="string token">"""
f = os.path.join(folder,case)
t =os.path.getmtime(f)
out = datetime.datetime.fromtimestamp(t)
out = '{:%Y_%m_%d %H:%M:%S}'.format(out)
return out
def os_walk(src_folder,ending="py"):
"""</SPAN>folder<SPAN class="punctuation token">,</SPAN> file type ending<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">return</SPAN> creation time<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> returns a message
Now walk the walk<SPAN class="punctuation token">,</SPAN> getting the files that have the specified ending
<SPAN class="punctuation token">(</SPAN>ie<SPAN class="punctuation token">.</SPAN> <SPAN class="operator token">*</SPAN><SPAN class="punctuation token">.</SPAN>py<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">in</SPAN> the folder <SPAN class="operator token">and</SPAN> its subfolders<SPAN class="punctuation token">.</SPAN>
<SPAN class="string token">""</SPAN>"
msg <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n.....File path: ..... {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>src_folder<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> folder<SPAN class="punctuation token">,</SPAN> subfolders<SPAN class="punctuation token">,</SPAN> files <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>walk<SPAN class="punctuation token">(</SPAN>src_folder<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
case_files <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN> f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> files <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN>ending<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> case_files<SPAN class="punctuation token">:</SPAN>
counter <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
msg <SPAN class="operator token">+=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\nFolder:... {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>folder<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> case <SPAN class="keyword token">in</SPAN> case_files<SPAN class="punctuation token">:</SPAN>
counter<SPAN class="operator token">+=</SPAN><SPAN class="number token">1</SPAN>
t <SPAN class="operator token">=</SPAN> mod_time<SPAN class="punctuation token">(</SPAN>folder<SPAN class="punctuation token">,</SPAN>case<SPAN class="punctuation token">)</SPAN>
msg <SPAN class="operator token">+=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n ({:02d}) {: <25s} {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>counter<SPAN class="punctuation token">,</SPAN>case<SPAN class="punctuation token">,</SPAN>t<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> case<SPAN class="punctuation token">,</SPAN>case_files
<SPAN class="keyword token">return</SPAN> msg
<SPAN class="comment token">#----------------------------------------------------------</SPAN>
<SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="string token">"""change the folder, ending etc below """</SPAN>
src_folder <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"F:\Writing_Projects"</SPAN> <SPAN class="comment token">#r"F:\\"</SPAN>
ending <SPAN class="operator token">=</SPAN> <SPAN class="string token">"py"</SPAN>
get_time <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token">#</SPAN>
msg <SPAN class="operator token">=</SPAN> os_walk<SPAN class="punctuation token">(</SPAN>src_folder<SPAN class="punctuation token">,</SPAN>ending<SPAN class="operator token">=</SPAN>ending<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> msg
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Oh yes... I forgot... highlight...copy...paste output into Notepad++, or your wordprocessor and print/save from there. I could write the code, but someone has to have homework.
Enjoy