Page 1 of 2 1 2 LastLast
Results 1 to 15 of 16

Thread: documents and settings

  1. #1
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382

    documents and settings

    Weet iemand hoe ik bepaal of de "directory" documents and settings bestaat???
    Hoe zit dat met die magische gelinkte mappen?

  2. #2
    Quote Originally Posted by EricLang View Post
    Weet iemand hoe ik bepaal of de "directory" documents and settings bestaat???
    Waarom wil je dat controleren?
    Je moet NOOIT werken met hard-coded directory benamingen als je werkt met Windows-mappen.

    Je kunt zoiets doen:
    Delphi Code:
    1. function GetSpecialFolder(FolderID: LongInt): string;
    2. var
    3.   Path: pchar;
    4.   idList: PItemIDList;
    5. begin
    6.   GetMem(Path, MAX_PATH);
    7.   SHGetSpecialFolderLocation(0, FolderID, idList);
    8.   SHGetPathFromIDList(idList, Path);
    9.   Result := string(Path);
    10.   FreeMem(Path);
    11. end;
    en dat aanroepen met een van de CSIDL uit dit lijstje:
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

  3. #3

  4. #4
    Senior Member Thaddy's Avatar
    Join Date
    Dec 2004
    Location
    Amsterdam
    Posts
    2,211
    Quote Originally Posted by rvk View Post
    en dat aanroepen met een van de CSIDL uit dit lijstje:
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    DIT lijstje: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    Werken aan Ansi support voor Windows is verspilde tijd, behalve voor historici.

  5. #5
    Quote Originally Posted by Thaddy View Post
    Dat is leuk en aardig maar:
    {CSIDL}: As of Windows Vista, these values have been replaced by KNOWNFOLDERID values.
    En als je vraagt of "C:\Document and Settings" nog bestaat ga ik er vanuit dat dit ook moet draaien op pre-Vista machines

    Anders kun je nét zo goed antwoorden dat de "Document and Settings" niet bestaat maar een link is.

  6. #6
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    Ik vraag de mappen op (TDirectory.GetDirectories) en krijg daar "documents and settings" bij.
    Wanneer ik dan de attributen opvraag van die map: crash met map bestaat niet.
    Jammer dat een map niet gewoon een map is...
    Dank voor de antwoorden!

  7. #7
    Je kunt vrij makkelijk controleren of de directory een symlink is.
    Controleer voor faSymLink in filegetattr.
    Zie http://www.delphibasics.co.uk/RTL.asp?Name=filegetattr

    Ik weet niet welke functie jij gebruikt om de attributen te controleren maar filegetattr zou dus niet mogen crashen, maar je kunt hem dus wel makkelijk overslaan.

    Een junction controleren (ook een soort symlink maar dan "anders") is geloof ik wat moeilijker.
    http://stackoverflow.com/questions/1...tion-in-delphi

  8. #8
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    filgetatt klapt op mijn c:\documents and settings (directorynotfound)

  9. #9
    Ik zie inderdaad dat FileGetAttr klapt op een symlink.

    Maar waarom gebruik je niet gewoon de Attr van TSearchRec??

    Deze routine:
    Delphi Code:
    1. procedure TForm1.Button1Click(Sender: TObject);
    2. var
    3.   Rec: TSearchRec;
    4. begin
    5.   if FindFirst('C:\*', faAnyFile, Rec) = 0 then
    6.   begin
    7.     repeat
    8.       if Rec.Attr and faDirectory > 0 then
    9.       begin
    10.         Memo1.Lines.Add(Rec.Name + ' ' + Rec.Attr.ToString);
    11.         if Rec.Attr and faSymLink > 0 then
    12.             Memo1.Lines.Add(Rec.Name + ' is a symbolic link')
    13.         else
    14.             Memo1.Lines.Add(Rec.Name + ' is not a symbolic link');
    15.       end;
    16.     until FindNext(Rec) <> 0;
    17.     FindClose(Rec);
    18.   end;
    19. end;
    geeft onder andere dit als resultaat:
    Code:
    Documents and Settings 9238
    Documents and Settings is a symbolic link
    Drivers 16
    Drivers is not a symbolic link
    Dus de Rec.Attr controleren op faSymLink werkt prima om een symlink te detecteren.

    (Je kunt deze FindFirst natuurlijk ook in een functie gebruiken om de Attr van één directory terug te geven)

  10. #10
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    ook filegetattr zegt dat de directory C:\documents and settings niet bestaat.

  11. #11
    Quote Originally Posted by EricLang View Post
    ook filegetattr zegt dat de directory C:\documents and settings niet bestaat.
    Ik heb het in mijn post hierboven toch over FindFirst?
    Heb je dat stukje code geprobeerd dat ik gaf?
    Die geeft aan dat C:\Document and Settings een symlink is.

  12. #12
    Senior Member Wok's Avatar
    Join Date
    Dec 2002
    Location
    Alkmaar
    Posts
    2,085
    Quote Originally Posted by EricLang View Post
    ook filegetattr zegt dat de directory C:\documents and settings niet bestaat.
    Gebuik je quote's eromheen?

    De spatie's in je naam blijven bij veel programma's opspelen...
    10.4.2, Delphi2010, of Lazarus 2.2.0

  13. #13
    Reader
    Join Date
    May 2002
    Location
    Holland
    Posts
    3,382
    Ik ga het inderdaad eens met FindFirst() proberen, want dit gaat niet...
    Code:
    Dirs := TDirectory.GetDirectories('C:\', '*.*', TSearchOption.soTopDirectoryOnly);
    for S in Dirs do
    begin
      att := TDirectory.GetAttributes(S, True); // auw
    end;

  14. #14
    John Kuiper
    Join Date
    Apr 2007
    Location
    Almere
    Posts
    8,747
    Oke. De nieuwe manier van bestanden ophalen in Delphi.

    Een bug in de functie?
    Delphi is great. Lazarus is more powerfull

  15. #15
    Ik heb het probleem gevonden.

    TDirectory.GetAttributes() is niet gemaakt voor symbolic link directories.

    Als eerste aanroep in TDirectory.GetAttributes() wordt CheckGetAttributesParameters(Path); gebruikt om te controleren of Path aan een aantal eisen voldoet.
    Daarvan is controle op het bestaan er één van.
    Delphi Code:
    1. if ExistsCheck and (not Exists(Path)) then
    2.     raise EDirectoryNotFoundException.CreateRes(@SPathNotFound);


    Dit is de oplossing om de controle op path te omzeilen:
    Delphi Code:
    1. Dirs := TDirectory.GetDirectories('C:\', '*.*', TSearchOption.soTopDirectoryOnly);
    2. for S in Dirs do
    3. begin
    4.   att := TFile.IntegerToFileAttributes(FileGetAttr(S, false));
    5. end;

Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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