May 09, 2024, 08:55:31 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


How to get 'special' Directories (Desktop, Windows, System, etc).

Started by billhsln, July 27, 2007, 02:23:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I downloaded Fletchies CTL pak, but it won't install since I no longer have IBasic Pro on my system.  I would think that there would be a way that we can get the path for these special directories in EBasic.

Any hints as to how this might be done.  I am looking to create a utility to take a Subdirectory on a CD and create a M3U file of the MP3's in that Directory onto the Desktop.  What I need to know is how to get the path to the Desktop and I thought that some one else might have a need to get to some of the other special directories.

Thanks,
Bill  :)
When all else fails, get a bigger hammer.

GWS

I haven't a clue how this works - it's from a rather old post by an unknown author:

'SPECIAL FOLDER LOCATION
/*
Const CSIDL_DESKTOP = &H0
Const CSIDL_INTERNET = &H1
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_MYDOCUMENTS = &HC
Const CSIDL_MYMUSIC = &HD
Const CSIDL_MYVIDEO = &HE
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
Const CSIDL_COMMON_STARTMENU = &H16
Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_COMMON_STARTUP = &H18
Const CSIDL_COMMON_DESKTOPDIRECTORY = &H19
Const CSIDL_APPDATA = &H1A
Const CSIDL_PRINTHOOD = &H1B
Const CSIDL_LOCAL_APPDATA = &H1C
Const CSIDL_ALTSTARTUP = &H1D
Const CSIDL_COMMON_ALTSTARTUP = &H1E
Const CSIDL_COMMON_FAVORITES = &H1F
Const CSIDL_INTERNET_CACHE = &H20
Const CSIDL_COOKIES = &H21
Const CSIDL_HISTORY = &H22
Const CSIDL_COMMON_APPDATA = &H23
Const CSIDL_WINDOWS = &H24
Const CSIDL_SYSTEM = &H25
Const CSIDL_PROGRAM_FILES = &H26
Const CSIDL_MYPICTURES = &H27
Const CSIDL_PROFILE = &H28
Const CSIDL_SYSTEMX86 = &H29
Const CSIDL_PROGRAM_FILESX86 = &H2A
Const CSIDL_PROGRAM_FILES_COMMON = &H2B
Const CSIDL_PROGRAM_FILES_COMMONX86 = &H2C
Const CSIDL_COMMON_TEMPLATES = &H2D
Const CSIDL_COMMON_DOCUMENTS = &H2E
Const CSIDL_COMMON_ADMINTOOLS = &H2F
Const CSIDL_ADMINTOOLS = &H30
Const CSIDL_CONNECTIONS = &H31
Const CSIDL_COMMON_MUSIC = &H35
Const CSIDL_COMMON_PICTURES = &H36
Const CSIDL_COMMON_VIDEO = &H37
Const CSIDL_RESOURCES = &H38
Const CSIDL_RESOURCES_LOCALIZED = &H39
Const CSIDL_COMMON_OEM_LINKS = &H3A
Const CSIDL_CDBURN_AREA = &H3B
Const CSIDL_COMPUTERSNEARME = &H3D
Const CSIDL_FLAG_PER_USER_INIT = &H800
Const CSIDL_FLAG_NO_ALIAS = &H1000
Const CSIDL_FLAG_DONT_VERIFY = &H4000
Const CSIDL_FLAG_CREATE = &H8000
Const CSIDL_FLAG_MASK = &HFF00
*/
Const CSIDL_SENDTO = &H9
Declare Import,SHGetSpecialFolderLocation(hwnd as UINT,nFolder as INT,ppITEMIDLIST as POINTER),int
Declare Import,SHGetPathFromIDList(pITEMIDLIST:POINTER,PATH:STRING),int
Declare Import,CoTaskMemFree(pidl:POINTER)
Sub GetSpecialFolder(nFolder:Int),String
     Istring path[260]
     Pointer Pidl
     Pointer Ppidl
     Ppidl = &Pidl
     SHGetSpecialFolderLocation(NULL,nFolder,Ppidl)
     SHGetPathFromIDList(Pidl,Path)
     CoTaskMemFree(Pidl)
   Return Path
EndSub
Window W1
OpenWindow(W1,0,0,600,400,@MINBOX,0,"Window",&Main)
CenterWindow W1
Int hDir
String Path,Name
Path=GetSpecialFolder(CSIDL_SENDTO)+"\\"
hDir=FindOpen(Path+"*.*")
If(hDir)
   Do
      Name=FindNext(hDir)
      If(Name<>".")&(Name<>"..")&(Name<>"")
            MessageBox W1,"",Path+Name
      EndIf
   Until Name=""
   FindClose hDir
EndIf
WaitUntil W1=0
End
Sub Main
   Select @MESSAGE
      Case @IDCLOSEWINDOW
         CloseWindow W1
   EndSelect
   Return
EndSub


Perhaps it might give you a clue ..  :)

Graham
Tomorrow may be too late ..

billhsln

Loaded the code, compiled and gave it a try.  What you found works and gives the exact result that I was looking for.

Thanks GWS, also to who ever did the original, but thanks to them also.  This will solve my problem.

Thanks again,
Bill
When all else fails, get a bigger hammer.

GWS

And here's another old post from Paul ..

QuoteWhen writing programs you must always keep in mind the 'target' machine. The target is any machine other than yours the program will be run on. One of the common programming mistakes I see is assuming where certain files will be on a system. For example Windows 95 and 98 rely heavily on the 'system' folder which is normally in c:\windows\system.

Notice that I said normally. Windows can actually be installed to a different drive and directory. Windows NT and XP use a system32 folder. So how is one to account for all of this?

Here is the method I use in my programs. The windows API has a function called SHGetSpecialFolderLocation that will return a value you can send to SHGetPathFromIDList to find out where most of the special folder locations are. To keep it simple I use a subroutine that takes care of the nasty bits.

SETID "CSIDLDESKTOP",0x0000
SETID "CSIDLPROGRAMS",0x0002
SETID "CSIDLCONTROLS",0x0003
SETID "CSIDLPRINTERS",0x0004
SETID "CSIDLPERSONAL",0x0005
SETID "CSIDLFAVORITES",0x0006
SETID "CSIDLSTARTUP",0x0007
SETID "CSIDLRECENT",0x0008
SETID "CSIDLSENDTO",0x0009
SETID "CSIDLBITBUCKET",0x000a
SETID "CSIDLSTARTMENU",0x000b
SETID "CSIDLDESKTOPDIRECTORY",0x0010
SETID "CSIDLDRIVES",0x0011
SETID "CSIDLNETWORK",0x0012
SETID "CSIDLNETHOOD",0x0013
SETID "CSIDLFONTS",0x0014
SETID "CSIDLTEMPLATES",0x0015
SETID "CSIDLCMNSTARTMENU",0x0016
SETID "CSIDLCMNPROGRAMS",0X0017
SETID "CSIDLCMNSTARTUP",0x0018
SETID "CSIDLCMNDESKTOPDIRECTORY",0x0019
SETID "CSIDLAPPDATA",0x001a
SETID "CSIDLPRINTHOOD",0x001b
DECLARE "shell32",SHGetSpecialFolderLocation(HWND:INT,nFolder:INT,LPITEMIDLIST:POINTER),int
DECLARE "shell32",SHGetPathFromIDList(ITEMIDLIST:INT,PATH:STRING),int
DECLARE "ole32",CoTaskMemFree(pidl:int)
REM Send this subroutine your window and one of
REM the ID's listed above and get back a path.
REM some ID's will not return a path such as
REM CSIDLCONTROLS since there really isn't a
REM 'control panel' folder.
SUB GetFolderLocation(win:WINDOW,nFolder:INT)
  DEF path:STRING
  DEF pidl:INT
  DEF ppidl:POINTER
  ppidl = pidl
  SHGetSpecialFolderLocation(win,nFolder,ppidl)
  SHGetPathFromIDList(pidl,path)
  CoTaskMemFree(pidl)
RETURN path


QuoteNow, for example, if you need to know the path to the user's desktop folder for creating an icon perhaps you can simply use:

path = GetFolderLocation(win,@CSIDLDESKTOP)

Now what about the system directory? Well you notice its not in the list of ID's. Thats because there already is a dedicated API function for it.

DECLARE "kernel32",GetSystemDirectoryA(path:STRING,size:INT),int
REM example
DEF syspath:STRING
GetSystemDirectoryA(syspath,255)


all the best, :)

Graham



Tomorrow may be too late ..

ts-soft

For WinDir or SysDir, you should not use GetSpecial Folder, is only with newer Internet Explorer avalaible! Better use this:
DECLARE IMPORT, _GetSystemDirectory ALIAS GetSystemDirectoryA(lpBuffer AS STRING,nSize AS INT),INT
DECLARE IMPORT, _GetWindowsDirectory ALIAS GetWindowsDirectoryA(lpBuffer AS STRING,nSize AS INT),INT

ISTRING WinDir[260]
ISTRING SysDir[260]

_GetWindowsDirectory(WinDir, 260)
_GetSystemDirectory(SysDir, 260)

OpenConsole

Print "Windows: ", WinDir
Print "Sytem:   ", SysDir

PRINT
PRINT "Press Any Key To Close"
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Sorry for my bad english

billhsln

Just wanted to say thank you to both GWS and ts-soft.

I used the info and came up with this utility to create M3U files on the Desktop.

Hope this code can help some one else out.

Thanks again,
Bill

/*  Compile as Windows.exe

This program prompts for a directory, then asks to save a M3U file
of extracted information, then it processes all files in the
directory picked, extracts info to write to the M3U file

*/

$MAIN
Def Version$:String:Version$=""
autodefine "off"

'declare types and functions
TYPE BROWSEINFO
    DEF hOwner:UINT
    DEF pidlRoot:UINT
    DEF pszDisplayName:POINTER
    DEF lpszTitle:POINTER
    DEF ulFlags:UINT
    DEF lpfn:UINT
    DEF lParam:INT
    DEF iImage:INT
ENDTYPE

DECLARE IMPORT,SHGetPathFromIDList(pidl:INT,pszPath:STRING),INT
DECLARE IMPORT,SHBrowseForFolder(lpbi:BROWSEINFO),INT
DECLARE IMPORT,CoTaskMemFree(pidl:INT)
DECLARE IMPORT,RtlZeroMemory(pData AS POINTER,length AS INT)
DECLARE IMPORT,SHGetSpecialFolderLocation(hwnd as UINT,nFolder as INT,ppITEMIDLIST as POINTER),int

DEF path[260] as ISTRING

DEF w1:WINDOW
DEF fn[260]:ISTRING

def OnScreen[27]:string

def filter, rtn:string
def Ifile, Ofile:file
def Spath, Npath, Cpath, nfilename:string
def dir, attrib, hfile, cnt, row, indx, i2:int
' Constants
CONST cBLACK   = 0
CONST cCYAN    = 0x00FF901E
CONST cHIWHITE = 0x00FFFFFF

CONST CSIDLDESKTOP = 0x0000

OPENWINDOW w1,0,0,640,480,0,0,"Create M3U file on Desktop",&hnd

SETFONT w1,"Courier New",12,400,0,0
SETWINDOWCOLOR w1, cBLACK
FRONTPEN w1, cCYAN
BACKPEN w1, cBLACK
MOVE w1,10,0
indx = -1
row = 0
' blank out array
for i2 = 0 to 26
OnScreen[i2] = ""
next i2
' get directory
Spath = GetFolder(w1, "Select directory...")
' if a directory has been selected then continue processing
if (Spath<>"")
' get output file to save data in
filter = "M3U Files (*.M3U)|*.M3U||"
path = GetFolderLocation(CSIDLDESKTOP)
nfilename = filerequest("Output File Name",0,0,filter,"M3U",0,path)
' check and make sure user picked a file
if (nfilename <> "")
' check for problem with open of file for Write
if (openfile(Ofile,nfilename,"W") <> 0)
PrintW1("File: " + nfilename + " Not able to Open Output")
PrintW1("***Program Aborted***")
else
' start processing files
cnt = 0
GetFilesFL(Spath)
closefile Ofile
PrintW1(fn)
PrintW1("---Program Done---")
endif
endif
else
PrintW1("Directory Select Cancelled")
endif

WAITUNTIL w1=0

END

'======
SUB hnd
'======
    'handler for the window w1
    SELECT @CLASS
        CASE @IDCREATE
            CENTERWINDOW w1
        CASE @IDCLOSEWINDOW
            CLOSEWINDOW w1
    ENDSELECT
    RETURN
ENDSUB

'=============================
SUB PrintW1(ToPrint as string)
'=============================
indx +=1
row = 0
if (indx > 27)
for i2 = 0 to 25
OnScreen[i2] = OnScreen[i2 + 1]
next i2
OnScreen[26] = ToPrint
indx = 26
else
OnScreen[indx] = ToPrint
endif
SETWINDOWCOLOR w1, cBLACK
for i2 = 0 to indx
move w1, 10, row
row +=15
print w1, OnScreen[i2]
next i2
wait 1
RETURN
ENDSUB

'==============================================
SUB GetFolder(win:WINDOW, title:STRING), STRING
'==============================================
'open a folderrequest dialog
DEF path[260] AS ISTRING
DEF pszPath AS INT
DEF bi:BROWSEINFO
DEF lpIDList:INT
DEF Buffer:STRING

    'initialize variables
    path[0] = 0
    RtlZeroMemory(bi,LEN(bi))
    bi.hOwner = win.hwnd
    bi.pszDisplayName = Buffer
    bi.lpszTitle = title
    bi.ulFlags = 0x00000001

'browse for folder
    lpIDList = SHBrowseForFolder(bi)
    IF lpIDList <> 0
        pszPath = SHGetPathFromIDList(lpIDList,path)
        CoTaskMemFree(lpIDList)
    ENDIF
    RETURN path
ENDSUB

'==========================
sub GetFilesFL(Path:string)
'==========================
def H, attrib, l:int
def Name, dir, temp:string

dir = Path + "\\*.MP3"
H = FindOpen(dir)
If (H)
Do
Name = FindNext(H,attrib)
if (attrib & @file_directory)
' If (Name <> "") and (Name <> ".") and (Name <> "..")
' gosub GetFilesFL(path + "\\" + Name)
' EndIf
else
if (Name > " ")
temp = path + "\\" + Name
write (Ofile, temp)
endif
endif
Until Name = ""
FindClose H
endif
return
endsub

'===========================================
SUB GetFolderLocation(nFolder as INT),STRING
'===========================================
DEF path[260] as ISTRING
DEF pidl as POINTER
DEF ppidl as POINTER
ppidl = &pidl
SHGetSpecialFolderLocation(NULL,nFolder,ppidl)
SHGetPathFromIDList(pidl,path)
CoTaskMemFree(pidl)
RETURN path
endsub
When all else fails, get a bigger hammer.

GWS

Thanks Bill - glad it worked for you.

Shows how much I know of these modern methods - I'd never heard of an 'm3u' file ..  ::)

I still play vinyl records ..  ::)

all the best, :)

Graham
Tomorrow may be too late ..

billhsln

M3U is the 'Playlist' format for Windows Media Player.  The file my program creates is a basic M3U file, nothing special or fancy, just full Drive/Directory/Filename.

Thanks again,
Bill
When all else fails, get a bigger hammer.