diff matlab/db/uniquefile.m @ 0:0dd31a8c66bd

Initial check in to Mercurial, V.1
author samer
date Fri, 13 Jan 2012 15:29:02 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matlab/db/uniquefile.m	Fri Jan 13 15:29:02 2012 +0000
@@ -0,0 +1,21 @@
+function fn=uniquefile(dt,root,dir,pattern)
+% uniquefile - Allocate a unique unused filename
+%
+% uniquefile :: 
+%	  [[1,6]] ~'date as returned by clock (currently not used)', 
+%	  path    ~'implicit root directory', 
+%	  path    ~'explicit directory relative to implicit root', 
+%	  string  ~'filepath pattern with exactly one %s somewhere to accept id'
+% -> path    ~'unique path relative to implicit root'.
+
+% SA 2005-04-25 Seems that 10000 files per directory is not enough..
+% SA 2008-06-27 Pattern must now contain %s, not %d.
+
+	exists=1;
+	numpat=sprintf(pattern,'%05d'); 
+	while exists,
+		fn=fullfile(dir,sprintf(numpat,floor(100000*rand)));
+		exists=exist(fullfile(root,fn),'file');
+	end
+
+