Search code examples
chilkat

chilkat - How to use Chilkat.FileAccess.FileDelete function to delete all file using *.*


I have the problem to use Chilkat.FileAccess.FileDelete to delete all file using ., the log says the following, how to handle the problem, thanks!

ChilkatLog: FileDelete: ChilkatVersion: 9.5.0.75 WindowsError: The filename, directory name, or volume label syntax is incorrect. failedToDeleteFilepath: C:\TMP\untar001*.* --FileDelete --ChilkatLog


Solution

  • You are passing wildcards to FileAccess.FileDelete, which doesn't accept wildcards. Unfortunately the Chilkat API doesn't provide means to enumerate files in a directory, so if you want to stick to the Chilkat API you would have to delete the entire directory:

    fa.DirDelete("C:\\TMP");
    

    Otherwise, using standard .NET:

    foreach (string file in Directory.EnumerateFiles(
        "C:\\TMP", 
        "untar001*.*" , 
        SearchOption.AllDirectories) 
        )
    {
        fa.FileDelete(file);
    }