Page 1 of 1

F4 - option to check the file size before editor is launched

Posted: 2018-01-13, 05:32 UTC
by petrklic
Sometimes, by mistake, I press F4 instead of F3 or F5 key on a large file. Would be nice if TC first checks if the selected file is over some size (user defined value) before launching the editor. Ie if the file is greater than 20 MB, show a dialog window to warn the user.

Is there an option already in TC or is there any possibility to implement this option?

Re: F4 - option to check the file size before editor is laun

Posted: 2018-01-13, 11:07 UTC
by Horst.Epp
petrklic wrote:Sometimes, by mistake, I press F4 instead of F3 or F5 key on a large file. Would be nice if TC first checks if the selected file is over some size (user defined value) before launching the editor. Ie if the file is greater than 20 MB, show a dialog window to warn the user.

Is there an option already in TC or is there any possibility to implement this option?
No, there is no such option and its not on the file manager to do so.
Many editors give you a warning on opening large or binary files
PSpad for example.

Posted: 2018-01-13, 14:47 UTC
by Hacker
petrklic,
You could use a simple script as your "editor" for F4 which would check the filesize and if it fits below the limit call the actual editor, example in AutoHotkey:

Code: Select all

Editor = C:\Program Files\Editor\Editor.exe
FileSizeLimitInBytes = 10000000

FileGetSize, FileSize, % A_Args[1]
IfLessOrEqual, FileSize, %FileSizeLimitInBytes%
	Run, % """" . Editor . """ """ . A_Args[1] . """"
HTH
Roman

Posted: 2018-01-13, 15:49 UTC
by gdpr deleted 6
No need for AutoHotKey or any other 3rd-party scripting solution.

A simple batch file like this should do:

Code: Select all

@echo off
if %~z1 lss <MaxFileSizeInBytes> (
	<PathToEditorExecutable> %1
) else (
	msg %SessionName% File too large for editor
)
Don't forget to replace the placeholders <MaxFileSizeInBytes> and <PathToEditorExecutable> with the respective values.

The batch file expects the file to open in the editor as (first) argument.

By the way, the message box opened by the "msg" command will auto-close after 60 seconds. I also do want to mention a rather minor annoyance of calling a batch file like this with F4 from TC: Whenever you press F4, for a very brief moment a console window will flash on your screen, which you might or might not notice and which you might or might not find annoying. If this is annoying to you, then you might want to use AutoHotKey or other tools that can avoid/suppress showing a (console) window when executing a script... ;)