הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Friday, April 23, 2010 6:36 PM
Hi some one know how to do this but with another path a customized and noy my documents?
http://msdn.microsoft.com/en-us/library/h63bz6ys%28VS.80%29.aspx
If you don´t Believe in it, Then it Doesn´t Exist!
All replies (15)
Sunday, April 25, 2010 10:41 AM ✅Answered
There is an example here:
http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx
Directory.Delete Method (String, Boolean)
Friday, April 23, 2010 6:49 PM
You can specify the My.Computer.FileSystem.GetFiles() to be a string. More info is here.
Dim strDirectory As String = "C:\Folder\Folder"
For Each foundFile As String In My.Computer.FileSystem.GetFiles(strDirectory, "*.*")
My.Computer.FileSystem.DeleteFile(foundFile, FileIO.UIOption.AllDialogs, FileIO.RecycleOption.DeletePermanently)
Next
v/r LikeToCode....Mark the best replies as answers.
Friday, April 23, 2010 6:51 PM
Read this note there :
Use the My.Computer.FileSystem.GetFiles method to return the collection of strings representing the files in the directory.
It depends on you how you want to input path. Your options are :
Using a FolderBrowserDialog.
Example :
Dim path as string
If FolderBrowserDialog1.ShowDialog() = DialogResults.Ok Then
path = FolderBrowserDialog1.Selectedpath
End if
Now path variable holds user selected path. Put it as argument for GetFiles()
If you want to hardcode path. You can anytime put it has getFiles("C:\MyFolder")
If you want folder relative to your application installation directory, you could do it like
path as string = Application.StartupPath & "\yourFolder\anotherFolder"
pass path variable to getFiles() method.
Thanks
"Feel the Force !" | My blog
Friday, April 23, 2010 6:54 PM
Just change the parameter for the my document to directory you want to remove. You can use FolderBrowserDialog to get the path and pass the name to the code.
Dim fb as new As New System.Windows.Forms.FolderBrowserDialog
If fb.ShowDialog=Windows.Forms.DialogResult.OK Then
For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
fb.SelectedPath,FileIO.SearchOption.SearchAllSubDirectories, "*.*")
My.Computer.FileSystem.DeleteFile(foundFile, _
FileIO.UIOption.AllDialogs, _
FileIO.RecycleOption.DeletePermanently)
Next
End IF
kaymaf
CODE CONVERTER SITE
http://www.carlosag.net/Tools/CodeTranslator/.
http://www.developerfusion.com/tools/convert/csharp-to-vb/.
Friday, April 23, 2010 6:56 PM
Another way that you can do it is this: If you want to delete everything in the folder, why not just delete the entire folder, then turn around and rebuild it. I do that often with temp folders that I create:
If My.Computer.FileSystem.DirectoryExists(tempZipFolder) Then
My.Computer.FileSystem.DeleteDirectory(tempZipFolder, FileIO.DeleteDirectoryOption.DeleteAllContents)
End If
My.Computer.FileSystem.CreateDirectory(tempZipFolder)
Friday, April 23, 2010 7:01 PM
Another way that you can do it is this: If you want to delete everything in the folder, why not just delete the entire folder, then turn around and rebuild it. I do that often with temp folders that I create:
If My .Computer.FileSystem.DirectoryExists(tempZipFolder) Then My .Computer.FileSystem.DeleteDirectory(tempZipFolder, FileIO.DeleteDirectoryOption.DeleteAllContents) End If My .Computer.FileSystem.CreateDirectory(tempZipFolder)
Do not ignore
FileIO.SearchOption.SearchAllSubDirectories parameter passed to GetFiles()
what if there's a complex folder structure inside ? how would you get it back ? Using that parameter you could delete all the files matching to specified filter and keeping folder structure as it is :-)
Thanks
"Feel the Force !" | My blog
Friday, April 23, 2010 7:04 PM
okeyy....i cant do rmdir cause that wont delete the files insideIf you don´t Believe in it, Then it Doesn´t Exist!
Friday, April 23, 2010 7:06 PM
@ Omie ->
Good point there. I wasn't thinking as all of my 'temp files' are all simple subfolders I create from the user's application folder.
Friday, April 23, 2010 7:11 PM
okeyy....i cant do rmdir cause that wont delete the files inside If you don´t Believe in it, Then it Doesn´t Exist!
You cant do what? Try to typing out the word. This is not social network where people get lazy to typing out simple word and forum does not have characters limit.
kaymaf
CODE CONVERTER SITE
http://www.carlosag.net/Tools/CodeTranslator/.
http://www.developerfusion.com/tools/convert/csharp-to-vb/.
Friday, April 23, 2010 7:13 PM
i meant the code: Rmdir("C:\test\)
if there is a file in it it wont work and i want to delte all files in the fodler.
Get it xD
If you don´t Believe in it, Then it Doesn´t Exist!
Friday, April 23, 2010 7:15 PM
hey kaymaf !
its not a shortform, its a command. rmdir .
Although I'm confused how that comment is related to code in question.
Thanks
"Feel the Force !" | My blog
Friday, April 23, 2010 9:36 PM
There is some weird stuff showing up in the help files lately. VB has enhanced file and directory handling. Use DeleteDirectory.
Sunday, April 25, 2010 10:05 AM
How do i use DeleteDirectoryIf you don´t Believe in it, Then it Doesn´t Exist!
Sunday, April 25, 2010 11:03 AM
Frank has already given you friday a complete sample on you in this message thread.
That would be my first approach also.
Success
Cor
Friday, August 8, 2014 10:26 AM
>>>>>>>>>>>>Here is The Best Way to Clear or Clean A folder<<<<<<<<<<
Dim s As String
For Each s In System.IO.Directory.GetFiles("C:\your\folder\link")
System.IO.File.Delete(s)
Next s
or the Basic Way
Kill("C:\your\folder\link")
Hope i Helped :)