Solved

Use .NET to delete tilde files

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

730 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