Recent

Author Topic: Making a text file  (Read 1939 times)

DumDum

  • New member
  • *
  • Posts: 32
Making a text file
« on: January 07, 2018, 09:30:13 pm »
Hi,

Just curious how one would go about writing a textfile to any persons desktop.

I know how to assign a file to my specific desktop however if I wanted to assign it to anyone using my program on their computer how would I go about doing that?

jamie

  • Hero Member
  • *****
  • Posts: 1131
Re: Making a text file
« Reply #1 on: January 07, 2018, 09:51:41 pm »
For a windows user look at this thread..

http://forum.lazarus-ide.org/index.php?topic=33739.0

I seem to remember there was a ready made function that was cross platform but what ever.

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: Making a text file
« Reply #2 on: January 07, 2018, 10:24:02 pm »
Hi,

Just curious how one would go about writing a textfile to any persons desktop.

I know how to assign a file to my specific desktop however if I wanted to assign it to anyone using my program on their computer how would I go about doing that?
on windows you use the SHGetFolderPath and pass the CSIDL_COMMON_DESKTOPDIRECTORY as the id for your folder. Specifically on windows 7 that should return something along the lines of c:\Users\All Users\Desktop
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

lainz

  • Hero Member
  • *****
  • Posts: 2960
    • Home
Re: Making a text file
« Reply #3 on: January 07, 2018, 10:30:24 pm »
That folder (At least on Windows 10) has administrative privileges to rename or create files.

C:\Users\Public\Desktop

bylaardt

  • Sr. Member
  • ****
  • Posts: 269
Re: Making a text file
« Reply #4 on: January 07, 2018, 10:32:17 pm »
whats wrong with
Code: Pascal  [Select]
  1. sysutils.GetUserDir()
?

lainz

  • Hero Member
  • *****
  • Posts: 2960
    • Home
Re: Making a text file
« Reply #5 on: January 07, 2018, 10:34:46 pm »
whats wrong with
Code: Pascal  [Select]
  1. sysutils.GetUserDir()
?

That is not the desktop folder as requested.

That is the user directory.

bylaardt

  • Sr. Member
  • ****
  • Posts: 269
Re: Making a text file
« Reply #6 on: January 07, 2018, 10:54:51 pm »
Ok, but windows have a internal dictionary to convert
Code: Pascal  [Select]
  1. sysutils.GetUserDir()+'Desktop'+DirectorySeparator+filename+fileextension
  2.  
to the right filename name, haven't?
I really don't use windows since xp, but if i remember, %HOMEPATH%\Desktop goes to desktop even when desktop folder has another name.

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: Making a text file
« Reply #7 on: January 07, 2018, 10:57:31 pm »
I know how to assign a file to my specific desktop however if I wanted to assign it to anyone using my program on their computer how would I go about doing that?
getuserdir or %home% or what ever does not add a file to all users.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bylaardt

  • Sr. Member
  • ****
  • Posts: 269
Re: Making a text file
« Reply #8 on: January 07, 2018, 11:04:51 pm »
@Dumdum
supposed to be "all" or "any"?
now i'm confused

lainz

  • Hero Member
  • *****
  • Posts: 2960
    • Home
Re: Making a text file
« Reply #9 on: January 07, 2018, 11:14:36 pm »
Ok, but windows have a internal dictionary to convert
Code: Pascal  [Select]
  1. sysutils.GetUserDir()+'Desktop'+DirectorySeparator+filename+fileextension
  2.  
to the right filename name, haven't?
I really don't use windows since xp, but if i remember, %HOMEPATH%\Desktop goes to desktop even when desktop folder has another name.

@Dumdum
supposed to be "all" or "any"?
now i'm confused

At least that folder does not have administrator permissions.