Grasshopper

algorithmic modeling for Rhino

Hi

I have one question for scripting.

Is rhino python support sort time ???  I have a list of text files by different time inside one folder.  I want  grasshopper script to read the latest  text file inside one folder.

I have check some solution in python

here is example :

files = os.listdir(".") 
files
.sort(key=os.path.getmtime, reverse=True)

for name in files: with open(name) as f:
if search_string in f.read():
print name
break

anyway to translate to rhinopython code ???

many thanks.
best,

Carl

Views: 1400

Replies to This Discussion

hi Carl, can you try this one?

import os
path = 'c:/python-test/'    #change this path

files = os.listdir(path + '.')
files = [path+x for x in files]
files = sorted(files,key=os.path.getmtime)[::-1]

for i in files:
    print i

Hi  Peter

many thanks for help.  So sorry for rely after  many months .

I have tried it.  it doesn't support import OS   said  syntax error

is there any idea ?

many thanks.

best

Carl

Carl,

It's not a problem with your 'import' call. It's a problem with indentation.

It looks like form your picture that you have a tab in front of "import os". And all of the other lines for that matter...

Check out the indentation rules for coding in Python here:

https://docs.python.org/release/2.5.1/ref/indentation.html

many thanks .

it works now.

hi ! 

could you please send the latest version of your code I'm trying to do the same thing in python grasshopper, getting errors :(

 I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog!

wuxiaworld

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service