another blog


About Microsoft Dynamics GP :-)

How to find the names of all text file in a folder in Microsoft Dexterity.

In Microsoft Dexterity we have a function Path_SelectPathname to select folder path.

According to the manual description of the function:The Path_SelectPathname() function displays a file dialog box, allowing a user to indicate the location of a file, and returns a generic pathname to that location.

But there is no way in Sanscript that we can find the contents of the folder, like to list down any specific extension files, Although it’s a common need to read text files in dexterity, so if user needs to read multiple text files inside Dexterity then he needs to select each file by using getfile() function individually, that’s not a real life situation. SO the below is a work around where user will tell the folder path and system will read all the text files of the folder. Not coding a whole scenario, just the key part of reading files names from folder.

For this particular situation we will use VBScript and Batch file, my favorite command line commands. :)I am using Sanscript function Dict_GetPathname(PATH_DATAFOLDER) to create batch file there, also vbs file will be copied there, So this could be changed according to your choice of option for saving vbs and batch files. More details of the function will be read from Dexterity Manuals. In debug mood it means you have to copy your vbs file in the folder where your dictionary is.

Open a notepad and past following line, replace the path “E:\New Working\Almas gp2010\” with your Dictionary folder path and save as listfiles.vbs

Set objShell = WScript.CreateObject(“WScript.Shell”)
objShell.Run(“””E:\New Working\Almas gp2010\command.bat”””), 0, True

open your dexterity window and copy below code in folder path select button.This will create a text file having names of all the text files inside selected folder, which then can be read through TextFile_ReadLine() function with a while loop .There should be other checks added in code like if user not selects folder path then abort script  or etc, add them according to your needs. 🙂

local integer l_File_ID;
local string com,l_Path,l_listFile,b_path,path;
local boolean result;

result = Path_SelectPathname(l_Path);
if result = true then
    FilePath of window ies_selectfolder of form ies_selectfolder = Path_MakeNative(l_Path);
end if;
path=FilePath of window ies_selectfolder of form ies_selectfolder;
l_File_ID=TextFile_Open(b_path+”command.bat”, 0, 2);
TextFile_WriteLine(l_File_ID, “E:”);
TextFile_WriteLine(l_File_ID, “dir /s/b “””+path+”*.txt””>”+””””+b_path+”text.txt”+””””);
run application “”,b_path+”listfiles.vbs”;


Filed under: Dexterity Development, dynamics-gp, , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: