Page 1 of 1

Access the user's AppData folder

PostPosted: Thu Dec 04, 2014 12:11 pm
by fkapnist
The Windows AppData folder is a hidden directory where your programs can store read/write data. Unlike the Windows Temp folder, the AppData folder is not immediately erased each time the program closes. It theoretically stays there until and if your program is finally uninstalled. So how do you write to and read from the AppData folder if it is hidden? I found a quick solution that seems to work for me: to create a new variable AppDataPath.



Code: Select all
SetVar "[CurrentDir]" "[TempDir]"
FileWrite "[TempDir]getdata.cmd" "1" "echo %APPDATA%>apdat.txt"
Run "[TempDir]getdata.cmd" "" "Hidden" "" ""
FileToVar "apdat.txt" "[GetAppDataDir]"
.extracting to trim the string's paragraph line break
ExtractFilePath "[GetAppDataDir]*.*" "[AppDataPath]"
.After this point you should be able to use the new variable AppDataPath to write to and read from the user's hidden AppData folder.

.Please disable the Alert, FileWrite and TextWindow demos below by adding a period to the start of each line (or erase them when done testing).
AlertBox "" "[AppDataPath]         <---this is the path (stored in new variable AppDataPath) to the current user's AppData folder."
FileWrite "[AppDataPath]test.txt" "All" "This demo file (test.txt) is now in the current user's hidden AppData folder. Files written here are not deleted as in the Temp folder. Put this NeoBook code in your startup action (without the demo Alerts). Use the new variable AppDataPath to write to and read from the hidden AppData folder!"
TextWindow "" "-1" "-1" "450" "500" "[AppDataPath]test.txt" "Wordwrap"



Paste the above code into a NeoBook Action script and try it out....

:idea:
..

Re: Access the user AppData folder

PostPosted: Thu Dec 04, 2014 12:22 pm
by fkapnist
fkapnist wrote:The Windows AppData folder is a hidden directory where your programs can store read/write data. Unlike the Windows Temp folder, the AppData folder is not immediately erased each time the program closes. It theoretically stays there until and if your program is finally uninstalled. So how do you write to and read from the AppData folder if it is hidden? I found a quick solution that seems to work for me: to create a new variable AppDataPath.



Code: Select all
SetVar "[CurrentDir]" "[TempDir]"
FileWrite "[TempDir]getdata.cmd" "1" "echo %APPDATA%>apdat.txt"
Run "[TempDir]getdata.cmd" "" "Hidden" "" ""
FileToVar "apdat.txt" "[GetAppDataDir]"
.extracting to trim the string's paragraph line break
ExtractFilePath "[GetAppDataDir]*.*" "[AppDataPath]"
.After this point you should be able to use the new variable AppDataPath to write to and read from the user's hidden AppData folder.

.Please disable the Alert, FileWrite and TextWindow demos below by adding a period to the start of each line (or erase them when done testing).
AlertBox "" "[AppDataPath]         <---this is the path (stored in new variable AppDataPath) to the current user's AppData folder."
FileWrite "[AppDataPath]test.txt" "All" "This demo file (test.txt) is now in the current user's hidden AppData folder. Files written here are not deleted as in the Temp folder. Put this NeoBook code in your startup action (without the demo Alerts). Use the new variable AppDataPath to write to and read from the hidden AppData folder!"
TextWindow "" "-1" "-1" "450" "500" "[AppDataPath]test.txt" "Wordwrap"



Paste the above code into a NeoBook Action script and try it out....

:idea:
..



If you remove the last FileWrite action (after having run the script at least once) you will see that the TextWindow action below it continues to display the text message because it is has been stored as a file in the user's AppData folder... Good...

:P

..

Re: Access the user's AppData folder

PostPosted: Thu Dec 04, 2014 1:53 pm
by fkapnist
The following NeoBook code will find the path to the user's AppData folder and list the contents of files in that folder:

Code: Select all
SetVar "[CurrentDir]" "[TempDir]"
FileWrite "[TempDir]getdata.cmd" "1" "echo %APPDATA%>apdat.txt"
Run "[TempDir]getdata.cmd" "" "Hidden" "" ""
FileToVar "apdat.txt" "[GetAppDataDir]"
.extracting to trim the string's paragraph line break
ExtractFilePath "[GetAppDataDir]*.*" "[AppDataPath]"
.After this point you should be able to use the new variable AppDataPath to write to and read from the user's hidden AppData folder.

.The lines below will list the contents of the user's AppData folder.
SetVar "[CurrentDir]" "[AppDataPath]"
DOSCommand "dir" ">appdata.txt" "Hidden"
Delay "500"
TextWindow "" "-1" "-1" "450" "500" "appdata.txt" "Wordwrap"


:!:

..

Re: Access the user's AppData folder

PostPosted: Thu Dec 04, 2014 2:09 pm
by stu
Thanks for the tip, but... Dude, you quote yourself within a minute of creating the thread and triple post yourself... :|

Re: Access the user's AppData folder

PostPosted: Thu Dec 04, 2014 2:53 pm
by fkapnist
stu wrote:Thanks for the tip, but... Dude, you quote yourself within a minute of creating the thread and triple post yourself... :|


Sorry, I'm new to this forum... I get things confused with Facebook Likes...... lol
:oops:
..