Copy folders with custom icons-VBForums
Results 1 to 22 of 22

Thread: Copy folders with custom icons

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Question Copy folders with custom icons

    Hi all, I'm new to all when it comes to coding and making my own programs.

    What I need help with is this:

    I have a folder structure located on my hd and I have made a program that copys that structure to another location like "clients"

    That's just so I don't have to create the same folder structure every time I get new clients or projects.

    I took my folder structure to the next level by creating custom icons for each folder "color codes folders for easy view" but now when I use the program everything works but the custom folder icons don't show in the new location.

    If I ctrl + C the structure and paste it on another location it works.


    Any idea why the icons don't follow ?
    Is vb just "copy names" and actually creates new folders with the same name ?

    I use the code "copyDirectoies"

    Best / Fredrik

  2. #2
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Copy folders with custom icons

    Please post your code if you would like help with this. "copyDirectoies" is not code.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Quote Originally Posted by kleinma View Post
    Please post your code if you would like help with this. "copyDirectoies" is not code.
    Sry about that, I'm on vb2013
    Code is this,
    my.computer.FileSystem.CopyDirectory("C:\TestDirectory1", "C:\TestDirectory2", True)

    Best / Fredrik

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Copy folders with custom icons

    So at what point do you create custom icons? that code above does nothing of the sort.

  5. #5
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Copy folders with custom icons

    First thing to check is to turn on hidden files and make sure it is also copying the desktop.ini file in each folder, as that is what contains the information on which custom icon to use for the given folder. If that is copying, and you were to say logout/login, or reboot, you would likely see the folders that you copied did copy over the custom icon and display it properly. To do it without restarting explorer, you can force an icon cache update:
    Code:
    Process.Start("ie4uinit.exe","-ClearIconCache")
    Note that if the given folder is displayed in an explorer window when you run that, you won't see it instantly change, but closing and reopening the folder should then display the correct custom icon. Works on Win7 and 8, not sure about prior versions.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Quote Originally Posted by kleinma View Post
    First thing to check is to turn on hidden files and make sure it is also copying the desktop.ini file in each folder, as that is what contains the information on which custom icon to use for the given folder. If that is copying, and you were to say logout/login, or reboot, you would likely see the folders that you copied did copy over the custom icon and display it properly. To do it without restarting explorer, you can force an icon cache update:
    Code:
    Process.Start("ie4uinit.exe","-ClearIconCache")
    Note that if the given folder is displayed in an explorer window when you run that, you won't see it instantly change, but closing and reopening the folder should then display the correct custom icon. Works on Win7 and 8, not sure about prior versions.
    Hi, thanks for your reply.
    Ive checked my settings and i have "Show hidden files" checked.
    But i cant see any desktop.ini even in the structure folders where i actually see the folder icons. And i dont see them in the project that i create either.


    Here is the full code:
    Sry for awful coding haha.

    Code:
    Public Class Form1
        Public prj_path As String
        Public str_path As String
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            prj_path = "D:\test\"
            str_path = "D:\__3D_Assets\__Project_Manager\_Structure\"
            For Each Dir As String In System.IO.Directory.GetDirectories(prj_path)
                Dim dirClients As New System.IO.DirectoryInfo(Dir)
                ComboBox1.Items.Add(dirClients.Name)
            Next
        End Sub
    
        Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
    
        End Sub
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    
        Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs)
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Browse_client.Click
            Form_Client.Show()
        End Sub
    
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ComboBox1.SelectedItem = ("") Then
                MessageBox.Show("You need to choose or create a client")
            ElseIf TextBox1.Text = "" Then
                MessageBox.Show("Please create sub project")
            ElseIf (My.Computer.FileSystem.DirectoryExists(prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text)) Then
                MessageBox.Show("Oh no!, You almost removed the whole project! Careful now!")
            Else
                MkDir(prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text)
                My.Computer.FileSystem.CopyDirectory(str_path, prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text, True)
                ProgressBar1.Value = 100
                MessageBox.Show("Project has been created")
            End If
    
        End Sub
    End Class




    Best / Fredrik

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    This is what i'm making.Name:  Structure.jpg
Views: 177
Size:  32.0 KB

  8. #8

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Quote Originally Posted by ident View Post
    iv already said you never add any icon.
    Yes you did, but as I said before. I'm trying to copy a folder Wich already have the icon assigned. I should not have to assign it via code, I should be able to copy the folder with the icon path.

    The desktop.ini is the answer but I don't know how to work that.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Got the Desktop.ini to show.

    This is what i see in the structure folders "With the icons"

    [.ShellClassInfo]
    IconResource=D:\__3D_Assets\__Project_Manager\_Folder_Icons\fromClient.ico,0
    [ViewState]
    Mode=
    Vid=
    FolderType=Generic


    This is what i see in the copied folders "Copied folders from program":

    [.ShellClassInfo]
    IconResource=D:\__3D_Assets\__Project_Manager\_Folder_Icons\fromClient.ico,0
    [ViewState]
    Mode=
    Vid=
    FolderType=Generic



    So it all looks right in there, it's linked to .ico


    How do i use this line
    Code:
    Process.Start("ie4uinit.exe","-ClearIconCache")

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Also, reboot didn't make any difference. copied folders is still regular icon but ini says IconResource=D:\__3D_Assets\__Project_Manager\_Folder_Icons\fromClient.ico,0

    Thats pretty strange i think

  12. #12
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Copy folders with custom icons

    Why would vb magically know the icon being used?

  13. #13

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Quote Originally Posted by ident View Post
    Why would vb magically know the icon being used?
    Because the desktop.ini that also is copied will carry the information that's already in the folder.
    That's at least the plan.

    Reading here now.http://msdn.microsoft.com/en-us/libr...02(VS.85).aspx

  14. #14
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Copy folders with custom icons

    so at wat point would my.computer.FileSystem.CopyDirectory("C:\TestDirectory1", "C:\TestDirectory2", True)testdirectory2 know any custom ini existed?

  15. #15

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Quote Originally Posted by ident View Post
    so at wat point would my.computer.FileSystem.CopyDirectory("C:\TestDirectory1", "C:\TestDirectory2", True)testdirectory2 know any custom ini existed?
    When the program has copied the folder structure to the new location, all of the folders has the desktop.ini in them.

    For example.
    This is in one of them:
    [.ShellClassInfo]
    IconFile=D:\__3D_Assets\__Project_Manager\_Folder_Icons\3d.ico,0
    [ViewState]
    Mode=
    Vid=
    FolderType=Generic

    All of the folders has the same code in the .ini exept that the "3d.ico" is changed to the corresponding folder name.

    Am i missing something here? I do not wich to assign the icon from VB program because the "Structure" will change alot and on alot of computers.
    That's why i choose to go with a complete structure on our server and just copy the whole thing to a new folder.

  16. #16
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Copy folders with custom icons

    what does the link say that you posted?



    1. Use PathMakeSystemFolder to make the folder a system folder. This sets the read-only bit on the folder to indicate that the special behavior reserved for Desktop.ini should be enabled. You can also make a folder a system folder from the command line by using attrib +s FolderName.

  17. #17

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Thank you, can you please help me how to use it?.
    Should that go in to .ini or in vb ?

    Sry i just don't understand how this things works

  18. #18

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    From the command promt i typed:

    attrib +s D:\test\var1\3\__fromClient

    Then it change the folder icon in the place were my program copied the folder.
    But i need to run that line for it to work.
    Is it possible via VB to run that line for all folders?

  19. #19
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: Copy folders with custom icons

    I didn't actually have to set the attribute to system folder in Win7 to get the custom icon to show, but I did in Win8.

    Here, this code works to copy the folder, and also set the system attribute.

    Code:
            Dim originalFolder As String = "C:\somedir\Original\"
            Dim copiedFolder As String = "C:\somedir\Copied\"
    
            My.Computer.FileSystem.CopyDirectory(originalFolder, copiedFolder, True)
    
            Dim PSI As New ProcessStartInfo("attrib.exe", "+s " & copiedFolder.TrimEnd("\"c))
            PSI.CreateNoWindow = True
            PSI.WindowStyle = ProcessWindowStyle.Hidden
            Process.Start(PSI)
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  20. #20

  21. #21

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    Think i just broke something.

    Now i can't even start the program even tough it's the same code as when i started.
    Getting this now:

    ------ Build started: Project: WindowsApplication1, Configuration: Debug Any CPU ------
    WindowsApplication1 -> C:\Users\Fredrik\Documents\Visual Studio 2013\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.exe
    C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(3578,5): error MSB3021: Unable to copy file "obj\Debug\WindowsApplication1.pdb" to "bin\Debug\WindowsApplication1.pdb". Access to the path 'bin\Debug\WindowsApplication1.pdb' is denied.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  22. #22

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    14

    Re: Copy folders with custom icons

    This is what i have atm. don't know what it does and it don't work :P

    Code:
    Public Class Form1
        Public prj_path As String = "D:\test\"
        Public str_path As String = "D:\__3D_Assets\__Project_Manager\_Structure\"
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            For Each Dir As String In System.IO.Directory.GetDirectories(prj_path)
                Dim dirClients As New System.IO.DirectoryInfo(Dir)
                ComboBox1.Items.Add(dirClients.Name)
            Next
        End Sub
    
        Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
    
        End Sub
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    
        Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs)
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Browse_client.Click
            Form_Client.Show()
        End Sub
    
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
    
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ComboBox1.SelectedItem = ("") Then
                MessageBox.Show("You need to choose or create a client")
            ElseIf TextBox1.Text = "" Then
                MessageBox.Show("Please create sub project")
            ElseIf (My.Computer.FileSystem.DirectoryExists(prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text)) Then
                MessageBox.Show("Oh no!, You almost removed the whole project! Careful now!")
            Else
    
    
                MkDir(prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text)
                My.Computer.FileSystem.CopyDirectory(str_path, prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text, True)
                Dim PSI As New ProcessStartInfo("attrib.exe", "+s " & prj_path + ComboBox1.SelectedItem & "\" & TextBox1.Text)
                PSI.CreateNoWindow = True
                PSI.WindowStyle = ProcessWindowStyle.Hidden
                Process.Start(PSI)
    
    
                ProgressBar1.Value = 100
                MessageBox.Show("Project has been created")
            End If
    
        End Sub
    End Class

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.