Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Folder on the Desktop 2

Status
Not open for further replies.

Danielvb

Programmer
Oct 8, 2002
34
US
Hi eveyone

Plaese I need some help.

I am writing a small application in Visual Basic 6.0. This applciation should be compatible with windows 98, Millenium, 2000, and XP.

The following task are:

1.- Create a folder(Accounting I) in the Desktop
2.- Copy two executables files to the folder that was create on the Desktop
a) c:\Sales\Account1.exe
b) c:\Sales\Account2.exe


====I hve a code but it gives me an error Path not found. What I am doing wrong?. Please, any tips it will be appreciate it. Thanks in advance for your time

Daniel
Hollywood, FL


==================
HERE IS THE CODE |
==================

Public Sub CreateAccountingFolder()
Dim fso As New FileSystemObject
If Not fso.FolderExists("\Desktop\Accouting I") Then
fso.CreateFolder "\Desktop\Accounting I"
End If
End Sub
 
in windows XP...
every user has a different Desktop...

which is located @...

\Documents and Settings\UserID\Desktop

Use the method in this (thread222-542981) thread to get the UserID

Not sure about W98/NT...

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Hi thanks for your time. Question please?

Is there is a way to search for the Desktop directory and get the path so that I can plug into my little coding. Please advice.

Thanks again...


Daniel
 
Yes. The following function will return the path to all the various special folders:
[tt]
Public Function GetSpecialPath(vdir As ShellSpecialFolderConstants) As String
Dim myShell As Shell32.Shell ' Requires reference to Microsoft Shell COntrols and Automation (SHDOC401.dll)

With New Shell32.Shell
' Should work for almost all versions of Shell32.dll (versions 4.71 and later)
GetSpecialPath = .NameSpace(vdir).ParentFolder.ParseName(.NameSpace(vdir).Title).Path
' If you have shell32.dll version 5.0 or later (XP, W2000, Windows Me) you can use the following instead:
' GetSpecialPath= .NameSpace(vDir).Self.Path
End With

End Function
[/tt]
For example, to get the common desktop folder:
[tt]
MsgBox GetSpecialPath(ssfCOMMONDESKTOPDIR)

 
Got a list of these constants? ssfCOMMONDESKTOPDIR

I tried the hex codes at link but some do and most do not work. Anyone have a list that works with this routine?

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
Er, you don't need a list if you are using my code. They are provided as an enumeration in the Microsoft Shell Controls and Automation library

Using the call example, when you type:

MsgBox GetSpecialPath(

you will then get a dropdown list of all the constants
 
Hmmm must be something peculiar to my pc then... for example:
ssfPERSONAL
causes runtime err 91, object variable or withblock variable not set.

Where as ssfMYPICTURES works and ssfDESKTOP does not.

Any ideas?

I'm using VB6 on XP pro and yes the projectg includes the reference "Microsoft Shell COntrols and Automation (SHDOC401.dll)"

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
On XP you should use the second, currently commented-out version since the library you are actually using comes from shell32.dll rather than SHDOC401.dll. In other words the comment line


' If you have shell32.dll version 5.0 or later (XP, W2000, Windows Me) you can use the following instead:


should read


' If you have shell32.dll version 5.0 or later (XP, W2000, Windows Me) you must/should use the following instead:


In later postings on this subject I clarified this, but clearly never updated this particular thread.

To be specific:

If Microsoft Shell Controls and Automation is sourced from SHDOC401.DLL (highlight the reference in the References dialog and you'll see where it comes from at the bottom) then use the first line:

GetSpecialPath = .NameSpace(vdir).ParentFolder.ParseName(.NameSpace(vdir).Title).Path

If, on the other hand, it is sourced from shell32.dll use the second variant:

GetSpecialPath= .NameSpace(vDir).Self.Path

 
Well I need the app to work on 98 and XP so i didnt switch the code but I can make the function a little smarter and use the different lines with diff OS's.

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
>make the function a little smarter

Yep. Very little of the example code I produce for tek-tips is designed with a multi-platform production environment in mind. Using it practically is often left as an exercise for the reader...:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top