Kaseya Community

Read, Store and Recall File Names in Procedures

  • Hi There,

    Does anybody know if its possible using an Agent Procedure to read the name of given file(s) in a folder then store them as a variable for later use in the script.

    I can output the folder list to a text file then use the File Content Variable which stores it in the log. But how can I search the log for the text in the file by preferably using wildcards. Is this possible?


    I'm dealing with an application that generates random file names but known extensions. I can rename the files as they will not be acknowledged correctly by the destination solution. I know I can simply zip them up and move them to their destination. But without knowing there file names I cannot report on there movement.



  • I dont think there is a way to do this purely with Kaseya script.

    When I need to get things like this done i will put together an AutoIT (a simple Basic-like scripting langage) and call it from my Kaseya script.

    Let me know if you need any help putting this together

  • Once you have retrieved the contents to a variable you can then use an If Step and check if the variable 'Contains' a certain value

  • Why don't you use a simple command like dir and cast it with for ?

    dir /s /b *.txt will list only the name of the file, then you could store it to a file like :

    dir /s /b *.txt >> list.txt -> Get File step to get the file in the agent for you

    Then with something like this :

    FOR /F "tokens=*" %G IN ('dir /b /s "c:\program files\*.txt"') DO echo %G to get their name one by one ?

    or to make one operation on each files you could use the for files commands

    forfiles /s /m *.* /c "cmd /c echo The extension of this @file is 0x09@ext"

    then use a little batch like that :


    set FILETOZIP=list.txt

       set TEMPDIR=C:\kworking\temp\

       rmdir %TEMPDIR%

       mkdir %TEMPDIR%

       copy %FILETOZIP% %TEMPDIR%

       echo Set objArgs = WScript.Arguments > _zipIt.vbs

       echo InputFolder = objArgs(0) >> _zipIt.vbs

       echo ZipFile = objArgs(1) >> _zipIt.vbs

       echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs

       echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs

       echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs

       echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs

       echo wScript.Sleep 2000 >> _zipIt.vbs

       CScript  _zipIt.vbs  %TEMPDIR%  C:\someArchive.zip



    For me that the easy way no ? ;)

  • Thanks Etienne, this has really helped me. Assuming I stored the contents of the output file into the procedure log and it looked something like this for three files:




    And I have transfered all three files to a destination folder on the host pr another Agent. Would you know how I would then go about recalling this out of the log to do something like a File Path command eg,

    File Path C:\Folder\Test\111110103018.AAA Exist

    I'm just trying to understand if it possible to now refer to the actual file name(s) themselves for subsequent procedure commands.