Jump to content

real-time file name validation


CyberSlug
 Share

Recommended Posts

This example warns you if you try to put one of the "forbidden" \ / : * ? " < > | characters in the box :)

I use message-loop mode, but you could easily adapt for onevent mode.

#include <GUIConstants.au3>

$GUI = GUICreate("Enter a name for a new folder....", 320,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); WS_EX_ACCEPTFILES
$file = GUICtrlCreateInput ( "", 10,  20, 300, 20)
$btn = GUICtrlCreateButton ("Ok", 40,  95, 60, 20)
GuiSetState(@SW_SHOW)

Dim $previousText

While 1
    $msg = GUIGetMsg()
    If $msg = $btn Or $msg = $GUI_EVENT_CLOSE Then Exit
    
    $text = GuiCtrlRead($file)
    If $previousText <> $text Then ToolTip("")
    
    If StringRegExp($text, '\\|/|:|\*|\?|\"|\<|\>|\|') Then
       GuiCtrlSetData($file, StringRegExpReplace($text, '\\|/|:|\*|\?|\"|\<|\>|\|', ""))
       DllCall ("user32.dll", "int", "MessageBeep", "int", 0xFFFFFFFF)  ;Beep
       Local $tooltipPos = WinGetPos($GUI)
       ToolTip("A file name cannot contain any of the following characters:" & @LF & _
                '              \ / : * ? " < > |', $tooltipPos [0]+160, $tooltipPos [1]+60, Default, Default, 3)
       $previousText = GuiCtrlRead($file)
    Endif
Wend
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Good example, nice and short.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Hi,

nice similar to this : http://www.autoitscript.com/forum/index.ph...c=31641&hl=

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...