Solved

Use .NET to delete tilde files

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now