All pastes #247740 Raw Edit

Miscellany

public text v1 · immutable
#247740 ·published 2006-11-13 20:46 UTC
rendered paste body
protected string GenRandomFileName (string basepath, string ext)
                {
                        if (rnd == null)
                                rnd = new Random ();
                        FileStream f = null;
                        string path = null;
                        do {
                                int num = rnd.Next ();
                                num++;
                                path = Path.Combine (basepath, num.ToString ("x"));
                                if (ext != null)
                                        path = String.Format ("{0}.{1}", path, ext);
                                        
                                try {
                                        f = new FileStream (path, FileMode.CreateNew);
                                } catch (System.IO.IOException) {
                                        f = null;
                                        continue;
                                } catch {
                                        throw;
                                }
                        } while (f == null);
                        f.Close ();
                        return path;
                }