-
Sep 17th, 2014, 12:14 PM
#1
Thread Starter
New Member
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
-
Sep 17th, 2014, 01:39 PM
#2
Re: Copy folders with custom icons
Please post your code if you would like help with this. "copyDirectoies" is not code.
-
Sep 17th, 2014, 01:51 PM
#3
Thread Starter
New Member
Re: Copy folders with custom icons
Originally Posted by kleinma
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
-
Sep 17th, 2014, 02:07 PM
#4
Re: Copy folders with custom icons
So at what point do you create custom icons? that code above does nothing of the sort.
-
Sep 17th, 2014, 02:09 PM
#5
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.
-
Sep 17th, 2014, 02:44 PM
#6
Thread Starter
New Member
Re: Copy folders with custom icons
Originally Posted by kleinma
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
-
Sep 17th, 2014, 02:48 PM
#7
Thread Starter
New Member
Re: Copy folders with custom icons
This is what i'm making.
-
Sep 17th, 2014, 03:10 PM
#8
Re: Copy folders with custom icons
iv already said you never add any icon.
-
Sep 17th, 2014, 03:13 PM
#9
Thread Starter
New Member
Re: Copy folders with custom icons
Originally Posted by ident
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.
-
Sep 17th, 2014, 03:34 PM
#10
Thread Starter
New Member
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")
-
Sep 17th, 2014, 03:43 PM
#11
Thread Starter
New Member
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
-
Sep 17th, 2014, 04:19 PM
#12
Re: Copy folders with custom icons
Why would vb magically know the icon being used?
-
Sep 17th, 2014, 04:25 PM
#13
Thread Starter
New Member
Re: Copy folders with custom icons
Originally Posted by ident
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
-
Sep 17th, 2014, 05:09 PM
#14
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?
-
Sep 17th, 2014, 05:15 PM
#15
Thread Starter
New Member
Re: Copy folders with custom icons
Originally Posted by ident
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.
-
Sep 17th, 2014, 05:16 PM
#16
Re: Copy folders with custom icons
what does the link say that you posted?
- 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.
-
Sep 17th, 2014, 05:23 PM
#17
Thread Starter
New Member
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
-
Sep 17th, 2014, 05:47 PM
#18
Thread Starter
New Member
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?
-
Sep 17th, 2014, 06:05 PM
#19
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)
-
Sep 17th, 2014, 06:06 PM
#20
Re: Copy folders with custom icons
-
Sep 17th, 2014, 06:24 PM
#21
Thread Starter
New Member
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 ==========
-
Sep 17th, 2014, 06:36 PM
#22
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|