File Joiner

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

File Joiner

Post by Phil Pendlebury » Fri Jan 11, 2013 7:29 pm

Sometimes we get bunches of files that are separated into 001,002,003,004 etc.

It is easy enough to use command line to deal with them but I wrote a little script that will join them for you (still using command line). Also the script will try to guess the file name.

Posting this as more examples of how to do things in dialogs.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
Let>RP_ADMIN=1
Let>APP_TITLE=Phil P File Joiner
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>MSG_WIDTH=400
Let>MSG_HEIGHT=210
Let>WF_TYPE=1
Let>VAREXPLICIT=0
Let>CF_OVERWRITE=1


Dialog>Dialog1
object Dialog1: TForm
  Left = 782
  Top = 345
  HelpContext = 5000
  BorderIcons = []
  BorderStyle = bsSingle
  Caption = 'File Joiner'
  ClientHeight = 192
  ClientWidth = 307
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 16
    Width = 238
    Height = 13
    Caption = 'Select the folder that contains the files to be joined'
  end
  object Label2: TLabel
    Left = 8
    Top = 72
    Width = 67
    Height = 13
    Caption = 'New Filename'
  end
  object Edit1: TEdit
    Left = 8
    Top = 40
    Width = 209
    Height = 21
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 226
    Top = 38
    Width = 75
    Height = 25
    Hint = 'Select folder to work in'
    Caption = 'Browse'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbFolder
  end
  object MSButton2: tMSButton
    Left = 5
    Top = 154
    Width = 140
    Height = 25
    Hint = 'Exit and Quit'
    Caption = 'Exit'
    TabOrder = 5
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 160
    Top = 154
    Width = 140
    Height = 25
    Hint = 'Join the files'
    Caption = 'Join!'
    TabOrder = 6
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit2: TEdit
    Left = 8
    Top = 92
    Width = 209
    Height = 21
    TabOrder = 2
    Text = 'Filename.txt'
  end
  object MSButton4: tMSButton
    Left = 226
    Top = 90
    Width = 75
    Height = 25
    Hint = 'Attempt to guess the filename and extension'
    Caption = 'Guess FN?'
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object CheckBox1: TCheckBox
    Left = 8
    Top = 123
    Width = 297
    Height = 17
    Caption = 'Delete Originals - *Deletes all files except New Filename!*'
    TabOrder = 4
  end
end
EndDialog>Dialog1

Let>INITDIR=C:\temp
SetDialogProperty>Dialog1,MSButton1,InitialDir,%INITDIR%
SetDialogProperty>Dialog1,Edit1,Text,%INITDIR%
Let>Selected_Folder=%INITDIR%

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,Quit
AddDialogHandler>Dialog1,MSButton4,OnClick,Guess
AddDialogHandler>Dialog1,MSButton3,OnClick,Go
AddDialogHandler>Dialog1,CheckBox1,OnClick,SureQ


Show>Dialog1,res

SRT>DoBrowse
 SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
 GetDialogProperty>Dialog1,MSButton1,Filename,Selected_Folder
 SetDialogProperty>Dialog1,Edit1,Text,Selected_Folder
END>DoBrowse

SRT>Guess
  Let>GFL_TYPE=0
  GetFileList>%Selected_Folder%\*.001,strFileList,;
  //
  IF>%strFileList%=
    MDL>Cannot find any files
    Goto>noguess
  ENDIF
  StringReplace>%strFileList%,%Selected_Folder%\,,OneFileName
  Separate>OneFileName,.,OneParts
  Let>ExtensionNum=OneParts_Count-1
  Let>Extension=OneParts_%ExtensionNum%
  Let>OriginalName=OneParts_1
  Let>New_Filename=%OriginalName%.%Extension%
  SetDialogProperty>Dialog1,Edit2,Text,%New_Filename%
  Label>noguess
END>Guess

SRT>Go
  GetFileList>%Selected_Folder%\*.001,strFileListX,;
  IF>%strFileListX%=
    MDL>There appears to be no files in that folder
    Goto>noguessx
  ENDIF
  GetDialogProperty>Dialog1,Edit2,Text,New_Filename
  GetDialogProperty>Dialog1,CheckBox1,Checked,destroy
  Run>cmd.exe /c copy/b "%Selected_Folder%"\*.* "%Selected_Folder%"\"%New_Filename%"
  //
  IF>%destroy%=True
   MoveFile>%Selected_Folder%\%New_Filename%,c:\temp\%New_Filename%
   DeleteFile>%Selected_Folder%\*.*
   MoveFile>c:\temp\%New_Filename%,%Selected_Folder%\%New_Filename%
  ENDIF
  //
  MDL>FINISHED :-)
  //
  Label>noguessx
  //
END>Go

SRT>SureQ
  GetDialogProperty>Dialog1,CheckBox1,Checked,ToF
  IF>%ToF%=True
    MDL>Please be aware that if this checkbox remains checked:%CRLF%%CRLF%ALL FILES in the selected folder will be DELETED%CRLF%%CRLF%Except the New Filename
  ENDIF
END>SureQ

SRT>Quit
  CloseDialog>Dialog1
  End
  Exit>0
END>Quit
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Sat Jan 12, 2013 1:36 pm

And here is an alternative version which is actually more functional.

This version will let you choose a "*.001" file and interpret the new filename from that (choice). Also this version will only work on the set of files that match the first file you selected. So you can have multiple sets in folder.

*Removed the delete files checkbox until I can do a better method

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
Let>RP_ADMIN=1
Let>APP_TITLE=Phil P File Joiner
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>MSG_WIDTH=440
Let>MSG_HEIGHT=210
Let>WF_TYPE=1
Let>VAREXPLICIT=0
Let>CF_OVERWRITE=1


Dialog>Dialog1
object Dialog1: TForm
  Left = 590
  Top = 289
  HelpContext = 5000
  BorderIcons = []
  BorderStyle = bsSingle
  Caption = 'File Joiner'
  ClientHeight = 164
  ClientWidth = 378
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 16
    Width = 269
    Height = 13
    Caption = 'Select the first file in the set to be joined (extension *.001)'
  end
  object Label2: TLabel
    Left = 8
    Top = 72
    Width = 67
    Height = 13
    Caption = 'New Filename'
  end
  object Edit1: TEdit
    Left = 8
    Top = 40
    Width = 364
    Height = 21
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 298
    Top = 62
    Width = 75
    Height = 25
    Hint = 'Select the first file of the set'
    Caption = 'Browse'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 5
    Top = 130
    Width = 140
    Height = 25
    Hint = 'Exit and Quit'
    Caption = 'Exit'
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 232
    Top = 130
    Width = 140
    Height = 25
    Hint = 'Join the files'
    Caption = 'Join!'
    TabOrder = 4
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit2: TEdit
    Left = 8
    Top = 92
    Width = 209
    Height = 21
    TabOrder = 2
    Text = 'myfilename.avi'
  end
end
EndDialog>Dialog1

Let>INITDIR=C:\temp
SetDialogProperty>Dialog1,MSButton1,InitialDir,%INITDIR%
SetDialogProperty>Dialog1,MSButton1,Filter,First in series|*.001


SetDialogProperty>Dialog1,Edit1,Text,%INITDIR%
Let>Selected_Folder=%INITDIR%

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,Quit
AddDialogHandler>Dialog1,MSButton4,OnClick,Guess
AddDialogHandler>Dialog1,MSButton3,OnClick,Go

AddDialogHandler>Dialog1,Edit1,OnChange,GetPath

AddDialogHandler>Dialog1,CheckBox1,OnClick,SureQ


Show>Dialog1,res

SRT>DoBrowse
 SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
 GetDialogProperty>Dialog1,MSButton1,Filename,Selected_File
 SetDialogProperty>Dialog1,Edit1,Text,Selected_File
END>DoBrowse

SRT>Go
  GetDialogProperty>Dialog1,Edit2,Text,New_Filename
  GetDialogProperty>Dialog1,CheckBox1,Checked,destroy
  Run>cmd.exe /c copy/b "%Selected_Folder%"\"%FileNoExt%.*" "%Selected_Folder%"\"%New_Filename%"
  MDL>FINISHED! :-)
END>Go

SRT>GetPath
  GetDialogProperty>Dialog1,Edit1,Text,PathTest
  IF>%PathTest%=
    GOTO>nopath
  ENDIF
  Separate>Selected_File,\,PathBits
  Let>LastC=PathBits_Count
  Let>Actual_File=PathBits_%LastC%
  StringReplace>%Selected_File%,%Actual_File%,,Selected_Folder
  //
  StringReplace>%Actual_File%,.001,,FileNoExt
  SetDialogProperty>Dialog1,Edit2,Text,%FileNoExt%
  Label>nopath
END>GetPath

SRT>SureQ
  GetDialogProperty>Dialog1,CheckBox1,Checked,ToF
  IF>%ToF%=True
    MDL>Please be aware that if this checkbox remains checked:%CRLF%%CRLF%ALL FILES in the set you chose from  the selected folder will be DELETED%CRLF%%CRLF%The new file will be retained
  ENDIF
END>SureQ

SRT>Quit
  CloseDialog>Dialog1
  End
  Exit>0
END>Quit
Phil Pendlebury - Linktree

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