简体   繁体   中英

vb.net - delete folder then create it, but not exists

In vs2010, there is a vb.net project, I need to clean a folder before use it, what I did is remote the folder, then create it again. but the problem is ,it is removed but not created again.

I think maybe .net did some optimization. So how can I fix that?

Here is the code:

    ' delete folder
    If IO.Directory.Exists(exportBaseFolder) = True Then
        IO.Directory.Delete(exportBaseFolder, True)
    End If

    ' create folder
    IO.Directory.CreateDirectory(exportBaseFolder)

You could try Directory.GetFiles and foreach file, file.delete. Then delete the folder. Then if not folder exists, create it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM