Source language: Translate to:

Access the user's AppData folder

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Access the user's AppData folder

Postby fkapnist » Thu Dec 04, 2014 12:11 pm

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:
..
Last edited by fkapnist on Thu Dec 04, 2014 12:23 pm, edited 1 time in total.
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: Access the user AppData folder

Postby fkapnist » Thu Dec 04, 2014 12:22 pm

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

..
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: Access the user's AppData folder

Postby fkapnist » Thu Dec 04, 2014 1:53 pm

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"


:!:

..
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: Access the user's AppData folder

Postby stu » Thu Dec 04, 2014 2:09 pm

Thanks for the tip, but... Dude, you quote yourself within a minute of creating the thread and triple post yourself... :|
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Access the user's AppData folder

Postby fkapnist » Thu Dec 04, 2014 2:53 pm

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:
..
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece


Return to NeoBook Action Commands

Who is online

Users browsing this forum: Bing [Bot] and 1 guest