Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Use .NET to delete tilde files

Posted on 2010-08-13
2
442 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:CSUGDEN
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
JayFromPep earned 125 total points
ID: 33430055
I am assuming you are talking about coding something that will do this.

If so, just loop through the files in the directory, check the name, and if it starts with a '~', delete it.

If it still complains, loop through the files and rename them if the name starts with a '~' to 'deleteme.doc' or whatever, then do a file.delete on 'deleteme.doc'.
0
 
LVL 5

Expert Comment

by:JayFromPep
ID: 33430174
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);
            }
        }
    }
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question