From: konsu Date: 2006-02-02T06:42:28+09:00 Subject: Re: check for and if not there, create direcory and file hello, a related question: how to make this atomic to avoid race conditions: Dir.mkdir(".timeclock") unless File.exist?(".timeclock") konstantin "Logan Capaldo" wrote in message news:DFC45DE6-0CCF-40CE-A21B-8BCCE7674C71@gmail.com... > > On Jan 30, 2006, at 12:09 PM, charlie bowman wrote: > >> irb(main):002:0> Dir.mkdir(".timeclock") >> won't the above faile once the directory is created. I need to run a >> check each time the application is ran. > > Yes, that's why you wrap it in an if (or unless) statement. > > unless File.exist?(".timeclock") > Dir.mkdir(".timeclock") > end > # Optionally make sure .timeclock is a directory > unless File.directory?(".timeclock") > puts ".timeclock is a not a directory." > exit( 1 ) > end > # do whatever. > > >