Search code examples
autoit

Opening RDP File With AutoIT


I am new to AutoIT, looking for some help to open RDP file. RDP files are available in my downloads folder. Most of the time I don't know my RDP file. I want to open the most recently downloaded RDP file. Can someone help me with the code? For now, I just tried to open RDP file by hardcoding the filename and it worked PFB the code but I need to find the most recently downloaded RDP file and open the same instead of hardcoding it.

Run("explorer.exe " & "C:\Users\Balaji\Downloads")
Run(@Comspec & " /c start " & FileGetShortName('C:\Users\1451615\Downloads\TestRDP.rdp'))

Solution

  • Try this! This should look into your downloads-folder for all files *.rdp and then sort the array, so you get the latest modified file and then Run it.

    #include <Array.au3>
    #include <File.au3>
    #include <MsgBoxConstants.au3>
    
    ;~ Global $downloadPath = 'C:\Users\Balaji\Downloads'
    Global $downloadPath = @UserProfileDir & '\Downloads'
    
    Global $rdpFiles = _FileListToArray($downloadPath, '*.rdp', $FLTA_FILES, True)
    
    Global $ar[UBound($rdpFiles)][2]
    
    For $i = 1 To UBound($rdpFiles) - 1
        $ar[$i][0] = $rdpFiles[$i]
        $ar[$i][1] = FileGetTime($rdpFiles[$i], $FT_MODIFIED, $FT_STRING )
    Next
    
    _ArraySort($ar, 1, Default, Default, 1)
    ; _ArrayDisplay($ar) ; If you want to have at look at the array
    
    Run($ar[0], '', @SW_MAXIMIZE)