Developing a Choose file dialog

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Developing a Choose file dialog

Post by gchichester » Fri Feb 26, 2016 2:20 pm

Would like to create a Choose file dialog that could do the following;
Use button on dialog screen to open a default folder with a list of files
Select file, copy, paste to another folder, rename
Set Focus back to MS Dialog screen

I looked at the Getfilelist, and the Dialogs - File Browse Example, but didn't help.
Thank you in advance for all your help
Gil

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Developing a Choose file dialog

Post by JRL » Fri Feb 26, 2016 5:21 pm

Would like to create a Choose file dialog that could do the following;
Use button on dialog screen to open a default folder with a list of files
Select file,....
The "Dialogs - File Browse Example" script does most of this part. The button used to open the browser has an "InitialDir" property. Set that to the directory you want to use as your default folder.

Once you select a file using your modified "Dialogs - File Browse Example" script rather than simply placing the selected file name in the edit field as the script does. Use the collected file name to:
(not) copy, (not) paste (but MoveFile>) to another folder, rename (using RenameFile>)
Set Focus back to MS Dialog screen
Perhaps you will have to create an edit object in which you type the new name for the file. Then another button to actually perform the MoveFile> and RenameFile>.

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Re: Developing a Choose file dialog

Post by zabros2020 » Fri Oct 14, 2016 6:18 am

If you are still looking for a simply solution, I've created a very simple dialog that does the following:
1,Select destination folder (if different to default)
2,Select source file
3,Once source file is selected, the file is renamed at its destination directory with a random number

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

Dialog>DialogFileBrowse
object DialogFileBrowse: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 226
  ClientWidth = 688
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object lblDestination: TLabel
    Left = 128
    Top = 32
    Width = 10
    Height = 13
    Caption = '//'
  end
  object lblSelectedFile: TLabel
    Left = 128
    Top = 80
    Width = 10
    Height = 13
    Caption = '//'
  end
  object lblGeneric: TLabel
    Left = 128
    Top = 127
    Width = 10
    Height = 13
    Caption = '//'
  end
  object btnBrowse: tMSButton
    Left = 34
    Top = 68
    Width = 75
    Height = 25
    Cancel = True
    Caption = 'Source file'
    TabOrder = 0
    DoBrowse = False
    InitialDir = 'C:\Temp\'
    BrowseStyle = fbOpen
  end
  object btnDestination: tMSButton
    Left = 32
    Top = 20
    Width = 75
    Height = 25
    Caption = 'Destination'
    TabOrder = 1
    DoBrowse = False
    InitialDir = 'C:\Temp\Temp'
    BrowseStyle = fbFolder
  end
  object btnClose: tMSButton
    Left = 33
    Top = 185
    Width = 75
    Height = 25
    Caption = 'Close'
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>DialogFileBrowse

Show>DialogFileBrowse

'=======================
'DIALOG LOOP
'============
let>i=0
Label>dialogLoop
  Add>i,1
  If>i<2
    GoSub>AddEvent
    GoSub>Populate
  EndIf
  Wait>0.1
  'User selected a file
  If>browseDone=1
    'use this to flow on to other tasks if needed
    'without the need to exit, set browseDone to 1(true)
    Goto>endLoop
  EndIf
Goto>dialogLoop
Label>endLoop
'=======================

SRT>AddEvent
  AddDialogHandler>DialogFileBrowse,btnBrowse,OnClick,Browse
  AddDialogHandler>DialogFileBrowse,btnDestination,OnClick,SelectDestination
  AddDialogHandler>DialogFileBrowse,btnClose,OnClick,CloseDialog
END>AddEvent

SRT>Populate
  GetDialogProperty>DialogFileBrowse,btnDestination,InitialDir,dirDestination
  SetDialogProperty>DialogFileBrowse,lblDestination,Caption,%dirDestination%
END>Populate

SRT>Browse
  SetDialogProperty>DialogFileBrowse,btnBrowse,DoBrowse,True
  GetDialogProperty>DialogFileBrowse,btnBrowse,Filename,userFileName
  SetDialogProperty>DialogFileBrowse,btnBrowse,DoBrowse,False
  Length>%userFileName%,Chk_Len

  If>Chk_Len>0
    GoSub>NameAtrbs
    Length>%dirDestination%,Chk_Len
    If>Chk_Len>0
      'overwrite existing file if exists
      Let>CF_OVERWRITE=1
      CopyFile>%userFileName%,%dirDestination%\
      If>CF_RESULT_CODE=0
        ExtractFileName>%userFileName%,strFileName
        RenameFile>%dirDestination%\%strFileName%,%dirDestination%\%newFileAttrbs%_%strFileName%
        'file
        SetDialogProperty>DialogFileBrowse,lblSelectedFile,Caption,%userFileName%
        SetDialogProperty>DialogFileBrowse,lblGeneric,Caption,Copy and rename was Successful!%CRLF%%CRLF%%dirDestination%\%newFileAttrbs%_%strFileName%
        SetDialogProperty>DialogFileBrowse,btnBrowse,Filename,%userFileName%
      Else
        'CF_RESULT
        SetDialogProperty>DialogFileBrowse,lblGeneric,Caption,ERROR! %CF_RESULT_CODE%
      EndIf
    Else
      'select destination
      SetDialogProperty>DialogFileBrowse,lblDestination,Caption,Select destination...
    EndIf
  Else
    SetDialogProperty>DialogFileBrowse,lblGeneric,Caption,No file selected!
  EndIf
    
END>Browse

SRT>SelectDestination
  SetDialogProperty>DialogFileBrowse,btnDestination,DoBrowse,True
  GetDialogProperty>DialogFileBrowse,btnDestination,Filename,dirDestination
  Length>%dirDestination%,Chk_Len
  If>Chk_Len>0
    SetDialogProperty>DialogFileBrowse,lblDestination,Caption,%dirDestination%
  Else
    'select destination
    SetDialogProperty>DialogFileBrowse,lblDestination,Caption,Select destination...
  EndIf
END>SelectDestination

SRT>NameAtrbs
  'define new file name atributes
  Sec>secs
  Min>mins
  Hour>hour
  Day>day
  Month>month
  Year>year
  Random>1000,genRan
  Let>newFileAttrbs=%secs%%mins%%hour%%day%%month%%year%_%genRan%
END>NameAtrbs

SRT>CloseDialog
  Exit>
END>CloseDialog
Loving MS's Capabilities!!!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts