0

I have been writing a code to remove common virus we are facing today, that simply puts all data into a special folder that shows no title. In fact it is a chr(160) in VB. When I get directory list it shows with and empty name but I cannot change its name or view its contents.

P.S. You can test this by creating a folder with name Alt+0160

For Each foldername In Directory.GetDirectories("d:\x\ ") 
    TextBox1.Text += foldername + vbCrLf 
    If fname = " " Then      
        FileIO.FileSystem.RenameDirectory(foldername, "temp")     
    End If 
Next
Mathemats
  • 1,185
  • 4
  • 22
  • 35
tayyab
  • 78
  • 1
  • 6
  • How are you trying to change it's name or view contents? Via code or through windows explorer? – mccainz Mar 03 '15 at 13:37
  • This was fine for me; I also could change the name and view the contents. How about posting some code of where you are stuck at? – Trevor Mar 03 '15 at 16:07
  • `For Each foldername In Directory.GetDirectories("d:\x\ ") TextBox1.Text += foldername + vbCrLf If fname = " " Then FileIO.FileSystem.RenameDirectory(foldername, "temp") End If Next` This is the simple code that iterate through the directories... I have created D:\x in which that special folder (with name alt+0160) exist. It shows the name but not the contents inside that folder or cannot rename that folder – tayyab Mar 04 '15 at 04:17
  • @mccainz I am accessing the folder through vb .net code, given in above comment. Through windows explorer i can access the contents but through code I cant – tayyab Mar 04 '15 at 04:20
  • When I do a dir from command prompt I can see the directory fine. - What is that space doing at the end of the directory path ("d:\x\ ")? – Mathemats Mar 23 '15 at 00:21

2 Answers2

1

You are doing a comparison against chr(160) and a space character. Try comparing fname to the non-breaking space character. chr(160) returns a char type, so you will need to make sure fname is of the same type.

For Each foldername In Directory.GetDirectories("d:\x\ ") 
    TextBox1.Text += foldername + vbCrLf 
    If fname = chr(160) Then      
        FileIO.FileSystem.RenameDirectory(foldername, "temp")     
    End If 
Next
Mathemats
  • 1,185
  • 4
  • 22
  • 35
1

Your on the right track, yes there is Chr(160). if you no where the directory is then use the straight forward method other wise search the give directory for all sub directory check each of their name, if you get a hit then rename it.

My.Computer.FileSystem.RenameDirectory("d:\x\" & Chr(160) & "\", "NewNameGoHere")
Or
        Dim path as string = "d:\x\" 
        Dim di As New IO.DirectoryInfo(path)
        Dim Drs() As IO.DirectoryInfo = di.GetDirectories()
        For Each dr As IO.DirectoryInfo In Drs
           if dr.name = chr(160) then
           My.Computer.FileSystem.RenameDirectory(path & dr.name & "\", "NewNameGoHere")
           end if
        Next
Ad Kahn
  • 551
  • 4
  • 6