GroundControl Sample Code


Sample Codes
FindWindowText - Finds the text within a window title  
DeleteDirectoryFiles - Deletes the files in a directory  
RenameFile - Renames a file in a directory  
FindInFile - Creates a list of files that contain a certain line of text  
DaysBack - Displays a message box with the date minus a certain number of days  
MoveFile - Moves a file to another location  


FindWindowText - Finds the text within a window title

// Acrasoft
// GroundControl Version 3.21
// Name: FindWindowText
// Desc: Finds text within a window title


OnError("Error")
RunProgram("Notepad.exe",Normal)

//Put the name of the window to search for on the next line.
PutVar(%n,"notepad")
Uppercase(%n,%n)

If(!GetFirstWindow(%w,All),GoTo("Error"))
Uppercase(%w,%w)
If(!TextContains(%w,%n),GoTo("NextWindow"),GoTo("Found"))

:NextWindow
If(!GetNextWindow(%w),Goto("End"))
Uppercase(%w,%w)
// MessageBox(%w)

If(!TextContains(%w,%n),GoTo("NextWindow"))
:Found
PutVar(%m,%n)
AddString(%m," found in window ")
AddString(%m,%w)
MessageBox(%m)
CloseWindow(%w)

:End
ExitMacro()

:Error
MessageBox("Error")

Back to Top


DeleteDirectoryFiles - Deletes the files in a directory

// Acrasoft
// GroundControl Version 3.21
// Name: DeleteDirectoryFiles
// Desc: Deletes the files in a directory


OnError("Error")

If(!GetFirstFileInDirectory("c:\yourdirectory\,"*.gc",%FILE),GoTo(:end))
:top
PutVar(%Path,"c:\yourpath\")
AddString(%Path,%FILE)
DeleteFile(%Path)
If(GetNextFileInDirectory(%FILE),GoTo(:top))

:end
ExitMacro()

:Error
MessageBox("Error")
 
Back to Top


RenameFile - Renames a file in a directory

// Acrasoft
// GroundControl Version 3.21
// Name: RenameFile
// Desc: Renames a file in a directory


OnError("Error")

FindFile(Filename,Path,%Path)
CopyFile(%Path,"NewFilenameAndPath")
DeleteFile(%Path)

:end
ExitMacro()

:Error
MessageBox("Error")
 
Back to Top


FindInFile - Creates a list of files that contain a certain string

// Acrasoft
// GroundControl Version 3.21
// Name: FindInFile
// Desc:
Creates a list of files that contain a certain line of text

OnError("Error")

If(!GetFirstFileInDirectory("C:\test","*.txt",%FILENAME),GoTo(:end))
PutVar(%Text,"The Search String was Found in these Files:")

:top
FindFile(%FILENAME,C:\test,%PATH)
OpenFile(1,%PATH)

:readtop
If(!ReadLine(1,%LINE),GoTo(:readend))
If(TextContains(%LINE,"test"),AddString(%Text,%FILENAME),GoTo(":readtop"))
AddString(%Text," ")
GoTo(":readtop")

:readend
CloseFile(1)
If(GetNextFileInDirectory(%FILENAME),GoTo(:top))

:end
MessageBox(%Text)
:Error
MessageBox("Error")
 
Back to Top


DaysBack - Displays a message box with the date minus a certain number of days

// Acrasoft
// GroundControl Version 3.21
// Name: DaysBack
// Desc: Renames a file in a directory


OnError("Error")

PutVar(%Daysback,"10")
GetDateTime(%Date,"%x",Today)
Repeat(DateMinusDay(%Date,"%x",%Date),%Daysback)
MessageBox(%Date)

:end
ExitMacro()

:Error
MessageBox("Error")
 
Back to Top


MoveFile - Moves a file to another location

// Acrasoft
// GroundControl Version 3.21
// Name: MoveFile
// Desc: Move a file to another location

OnError("Error")

If(!IsFileLocked("C:\GroundControl\readme.txt"))
   MessageBoxEx("File not locked",Information,OK)
   If(!FileExist("C:\TEMP\readme.txx"))
      MessageBoxEx("destination file does not exist",Information,OK)
      If(CopyFile("C:\GroundControl\readme.txt","C:\TEMP\readme.txx"))
         MessageBoxEx("copy file worked",Information,OK)
         If(FileExist("C:\TEMP\readme.txx"))

If(DeleteFile("C:\GroundControl\readme.txt"),MessageBoxEx("Success",Information,OK))
         EndIf
      EndIf
   EndIf
EndIf

:end
ExitMacro()

:Error
MessageBox("Error")
 

Back to Top