Link to home
Start Free TrialLog in
Avatar of Charles Sugden
Charles SugdenFlag for United States of America

asked on

Use .NET to delete tilde files

One of our production jobs gets a lot of tilde files (~*.doc) in its processing directory.
I'd like to remove them when this job starts up with a command like
         file.delete("~*.doc")

but .net complains with an error
             "Illegal characters in path."

How can I remove these files?
ASKER CERTIFIED SOLUTION
Avatar of JayFromPep
JayFromPep
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Something like....

    public void deleteBogusFiles(string targetDir)
    {
        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(targetDir);
        foreach (System.IO.FileInfo fi in di.GetFiles())
        {
            string fn = fi.Name.ToString;
            if (fn.StartsWith('~'))
            {
                System.IO.File.Delete(fn);
            }
        }
    }