6

Is there a way to "touch" a existing directory in Linux using python so that its modtime becomes the current system time?

From the command line this is the equivalent of touch $directory.

gnr
  • 2,324
  • 1
  • 22
  • 24

2 Answers2

7

os.utime() will allow you to set the atime and mtime of an existing filesystem object, defaulting to the current date and time.

os.utime(path)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
3

You can do that with os.utime:

now = time.time()
os.utime('/tmp/marker', (now, now))
radtek
  • 34,210
  • 11
  • 144
  • 111
myaut
  • 11,174
  • 2
  • 30
  • 62