Jump to content
Sign in to follow this  
Bert

File use history

Recommended Posts

Bert

Does anyone have a snippit of code that one can use to list the last files opened in a app? I want to have a list of the last 5 txt files opened in my editor I'm working on. This list would be displayed in a dropdown box. Anyone got something like that? I've looked around for a bit, and didn't see anything.

Share this post


Link to post
Share on other sites
SmOke_N

Does anyone have a snippit of code that one can use to list the last files opened in a app? I want to have a list of the last 5 txt files opened in my editor I'm working on. This list would be displayed in a dropdown box. Anyone got something like that? I've looked around for a bit, and didn't see anything.

Most non-commercial editors I've seen use Ini's to do this, that is, if you are talking about what your specific editor has opened.

If it is, then I would imagine it to be just a matter of adding an IniWrite before you execute the action to open, and on "Close" to IniDelete().


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Kerros

My thought would be to either make a text file with the last 5 files opened, or use a registry entry.

What I have done in the past is to do a _filereadtoarray, delete the first entry, add the new, and then overwrite the file will the new information.

This way it is also easy for the user to increase or decrease the number of files stored in the list as well.


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
Bert

My thought would be to either make a text file with the last 5 files opened, or use a registry entry.

What I have done in the past is to do a _filereadtoarray, delete the first entry, add the new, and then overwrite the file will the new information.

This way it is also easy for the user to increase or decrease the number of files stored in the list as well.

can I see a example of code? I somewhat understand what you are saying, but still somewhat confused.

Share this post


Link to post
Share on other sites
Kerros

Quick and very dirty

CODE

#include<Array.au3>

#include<File.au3>

Local $logfile = @ScriptDir&'\logfile.txt'

If Not FileExists($logfile) Then FileWrite($logfile, "")

; make file for testing

;~ FileWrite($logfile,'Test1'&@CRLF&'Test2'&@CRLF&'Test3'&@CRLF&'Test4'&@CRLF&'Test5'&@CRLF)

Local $files

_FileReadToArray($logfile, $files)

_ArrayDisplay($files)

_ArrayDelete($files,1)

_ArrayAdd($files,'Add new file here')

_ArrayDisplay($files)

FileDelete($logfile)

_FileWriteFromArray($logfile,$files,1)


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
Bert

Ok, I used what you gave me, and I came up with this. What I can't figure out is how to tie the short name, and the full file name so that when I have a file name selected, and I click the button, I get the full path name to the file.

#include<Array.au3>
#include<File.au3>
#include<String.au3>

dim $filelist ,$logfile = @ScriptDir&'\logfile.txt'
If Not FileExists($logfile) Then FileWrite($logfile, 'zzzz'&@CRLF&'zzzz'&@CRLF&'zzzz'&@CRLF&'zzzz'&@CRLF&'zzzz')
$select_file = FileOpenDialog("Select text file", @ScriptDir, "Text files (*.txt)", 3)
Local $files
_FileReadToArray($logfile, $files)
_ArrayDelete($files,1)
_ArrayAdd($files,$select_file)
_FileWriteFromArray($logfile,$files,1)
_FileReadToArray($logfile,$filelist)
$shortlist="|"
For $x = 1 to $filelist[0]
    if $filelist[$x] = 'zzzz' then 
        sleep(0)
    else        
        $string_A = StringInStr($filelist[$x], "\", 0, -1)
        $trimFleft = StringTrimLeft($filelist[$x], $string_A )
        $String2 = _StringInsert("|", $trimFleft,-1)
        $shortlist = $shortlist & $String2
    endif   
Next
;----------------------------------------------------------
#Region ### START Koda GUI section ### Form=
#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 364, 156, 193, 125)
$Combo1 = GUICtrlCreateCombo("Combo1", 64, 24, 241, 25)
GUICtrlSetData($Combo1, $shortlist)
$Button1 = GUICtrlCreateButton("Button1", 96, 80, 169, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0, "", "Clicking this button will show the full file path of the file displayed in the combo box here in this msgbox. How do I do this???")
    EndSwitch
WEnd
Edited by Volly

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.