Solved

Use .NET to delete tilde files

Posted on 2010-08-13
2
439 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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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