2014-01-16 3 views

ответ

2

Да, есть встроенная функция (что лично мне ужасно;): вы можете заполнить ListBox с методом DirList(). Вы можете указать маску (например, *.txt) и тип файла (скрытый, системный, подкаталог, диск, ...).

ListBox будет содержать разные совпадающие имена. Если вам нужно иметь список только для лечения и не нужно его показывать, вы можете скрыть его из текущего окна ...

Настоящей не визуальной альтернативой было бы обертывание родного Windows API /FindNextFile() функций и связанных структур.

Edit - ванильный каталог pbscript список:

Вот код, который я использую, чтобы получить список каталогов. Он имеет некоторые зависимости от манипуляций с битами, которые реализованы в моем коде некоторыми встроенными расширениями PBNI, которые трудно включить здесь, поэтому я предоставляю некоторые функции, основанные на pbscript (субоптимальные) из PFC, чтобы иметь рабочий код.

Ниже приведен пример вызова:

string lf[] 
getfiles("c:\temp", "*.txt", ref lf[]) 
messagebox("getfiles", "found "+ string(upperbound(lf[]))+ " files") 

of_getbit.srf

global type of_getbit from function_object 
end type 

forward prototypes 
global function boolean of_getbit (long al_decimal, unsignedinteger ai_bit) 
end prototypes 

global function boolean of_getbit (long al_decimal, unsignedinteger ai_bit);////////////////////////////////////////////////////////////////////////////// 
// 
// Function:  of_GetBit 
// 
// Access:    public 
// 
// Arguments: 
// al_decimal  Decimal value whose on/off value needs to be determined (e.g. 47). 
// ai_bit   Position bit from right to left on the Decimal value. 
// 
// Returns:  boolean 
//      True if the value is On. 
//      False if the value is Off. 
//      If any argument's value is NULL, function returns NULL. 
// 
// Description: Determines if the nth binary bit of a decimal number is 
//      1 or 0. 
// 
////////////////////////////////////////////////////////////////////////////// 
// 
// Revision History 
// 
// Version 
// 5.0 Initial version 
// 5.0.03 Fixed problem when dealing with large numbers (>32k) 
//    from "mod int" to "int mod" 
// 
////////////////////////////////////////////////////////////////////////////// 
// 
/* 
* Open Source PowerBuilder Foundation Class Libraries 
* 
* Copyright (c) 2004-2005, All rights reserved. 
* 
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted in accordance with the GNU Lesser General 
* Public License Version 2.1, February 1999 
* 
* http://www.gnu.org/copyleft/lesser.html 
* 
* ==================================================================== 
* 
* This software consists of voluntary contributions made by many 
* individuals and was originally based on software copyright (c) 
* 1996-2004 Sybase, Inc. http://www.sybase.com. For more 
* information on the Open Source PowerBuilder Foundation Class 
* Libraries see http://pfc.codexchange.sybase.com 
*/ 
// 
////////////////////////////////////////////////////////////////////////////// 

Boolean lb_null 

//Check parameters 
If IsNull(al_decimal) or IsNull(ai_bit) then 
    SetNull(lb_null) 
    Return lb_null 
End If 

//Assumption ai_bit is the nth bit counting right to left with 
//the leftmost bit being bit one. 
//al_decimal is a binary number as a base 10 long. 
If Int(Mod(al_decimal/(2 ^(ai_bit - 1)), 2)) > 0 Then 
    Return True 
End If 

Return False 

end function 

of_bitwiseand.srf

global type of_bitwiseand from function_object 
end type 

forward prototypes 
global function long of_bitwiseand (long al_value1, long al_value2) 
end prototypes 

global function long of_bitwiseand (long al_value1, long al_value2);////////////////////////////////////////////////////////////////////////////// 
// 
// Function:  of_BitwiseAnd 
// 
// Access:    public 
// 
// Arguments: 
// al_Value1  The first value to be used in the operation. (e.g. 55) 
// al_Value2  The second value to be used in the operation. (e.g. 44) 
// 
// Returns:  Long 
//      The result of the AND operation (e.g. 36) 
//      If either argument's value is NULL, function returns NULL. 
// 
// Description: Performs a bitwise AND operation (al_Value1 && al_Value2), 
//      which ANDs each bit of the values. 
//      (55 && 44) = 36 
// 
////////////////////////////////////////////////////////////////////////////// 
// 
// Revision History 
// 
// Version 
// 5.0 Initial version 
// 
////////////////////////////////////////////////////////////////////////////// 
// 
/* 
* Open Source PowerBuilder Foundation Class Libraries 
* 
* Copyright (c) 2004-2005, All rights reserved. 
* 
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted in accordance with the GNU Lesser General 
* Public License Version 2.1, February 1999 
* 
* http://www.gnu.org/copyleft/lesser.html 
* 
* ==================================================================== 
* 
* This software consists of voluntary contributions made by many 
* individuals and was originally based on software copyright (c) 
* 1996-2004 Sybase, Inc. http://www.sybase.com. For more 
* information on the Open Source PowerBuilder Foundation Class 
* Libraries see http://pfc.codexchange.sybase.com 
*/ 
// 
////////////////////////////////////////////////////////////////////////////// 

Integer  li_Cnt 
Long   ll_Result 
Boolean  lb_Value1[32], lb_Value2[32] 

// Check for nulls 
If IsNull(al_Value1) Or IsNull(al_Value2) Then 
    SetNull(ll_Result) 
    Return ll_Result 
End If 

// Get all bits for both values 
For li_Cnt = 1 To 32 
    lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt) 
    lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt) 
Next 

// And them together 
For li_Cnt = 1 To 32 
    If lb_Value1[li_Cnt] And lb_Value2[li_Cnt] Then 
     ll_Result = ll_Result + (2^(li_Cnt - 1)) 
    End If 
Next 

Return ll_Result 

end function 

getfiles.srf

type str_filetime from structure 
    ulong ul_LowDateTime 
    ulong ul_HighDateTime 
end type 

type str_win32_find_data from structure 
    unsignedlong fileattributes 
    str_filetime creationfile 
    str_filetime lastaccesstime 
    str_filetime lastwritetime 
    unsignedlong filesizehigh 
    unsignedlong filesizelow 
    unsignedlong reserved0 
    unsignedlong reserved1 
    character filename[260] 
    character altfilename[14] 
// character filename[520] 
// character altfilename[28] 
end type 

global type getfiles from function_object 
end type 

type prototypes 
Function ulong FindFirstFile(ref string lpszSearchFile, ref STR_WIN32_FIND_DATA lpffd) library "kernel32.dll" alias for "FindFirstFileW" 
Function long FindNextFile(ulong hfindfile, ref STR_WIN32_FIND_DATA lpffd) library "kernel32.dll" alias for "FindNextFileW" 
Function boolean FindClose(ulong hfindfile) library "kernel32.dll" 
end prototypes 

forward prototypes 
global function long getfiles (string as_path, string as_dos_mask, ref string as_files[]) 
end prototypes 

global function long getfiles (string as_path, string as_dos_mask, ref string as_files[]);/* Wrapper for the Win32 API FindFirst/FindNext/FindClose 

as_path   : the directory to search in 
as_dos_mask : a generic file joker needed by FindFirst (give '*.*' or empty string for all files) 
as_files[] : folder name Array (output parameter) 

returns : the array as_files[] size 
*/ 

ulong lul_handle 
str_win32_find_data str_find 
string ls_path_and_mask, ls_empty[] 
boolean lb_use_rx = false, lb_process = false 
boolean lb_isdir 
long ll_ret, ll_count = 0 

constant long MAX_PATH = 260 
constant long ALT_NAME_SIZE = 14 
constant ulong INVALID_HANDLE_VALUE = 4294967295 

constant long FILE_ATTRIBUTE_READONLY = 1    //0x0001 
constant long FILE_ATTRIBUTE_HIDDEN = 2     //0x0002 
constant long FILE_ATTRIBUTE_SYSTEM = 4     //0x0004 
constant long FILE_ATTRIBUTE_DIRECTORY = 16    //0x0010 
constant long FILE_ATTRIBUTE_ARCHIVE = 32    //0x0020 
constant long FILE_ATTRIBUTE_DEVICE = 64    //0x0040 - reserved 
constant long FILE_ATTRIBUTE_NORMAL = 128    //0x0080 
constant long FILE_ATTRIBUTE_TEMPORARY = 256   //0x0100 
constant long FILE_ATTRIBUTE_SPARSE_FILE = 512   //0x0200 
constant long FILE_ATTRIBUTE_REPARSE_POINT = 1024  //0x0400 
constant long FILE_ATTRIBUTE_COMPRESSED = 2048   //0x0800 
constant long FILE_ATTRIBUTE_OFFLINE = 4096    //0x1000 
constant long FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192 //0x2000 
constant long FILE_ATTRIBUTE_ENCRYPTED = 16384   //0x4000 
constant long FILE_ATTRIBUTE_VIRTUAL = 65536   //0x10000 reserved 

as_files[] = ls_empty[] 

str_find.filename=space(MAX_PATH) 
str_find.altfilename=space(ALT_NAME_SIZE) 
if as_dos_mask = "" then as_dos_mask = "*.*" 
if right(as_path, 1) <> "\" then as_path += "\" 
ls_path_and_mask = as_path + as_dos_mask 
lul_handle = FindFirstFile(ls_path_and_mask, str_find) 
if lul_handle <> INVALID_HANDLE_VALUE then 
    do 
     if of_bitwiseand(str_find.fileattributes, FILE_ATTRIBUTE_DIRECTORY) > 0 then goto label_continue 
     as_files[upperbound(as_files[])+1] = str_find.filename 
label_continue: 
     //remark : the FindNextFile find the next file in the directory order 
     // the alphabetical sort is not guaranteed 
     ll_ret = FindNextFile(lul_handle, str_find) 
    loop while ll_ret > 0 
    Findclose(lul_handle) 
end if 
return upperbound(as_files[]) 

end function 
+0

Прошло некоторое время, поэтому я могу ошибаться, но я думаю, что с помощью метода Listbox вы можете динамически создавать список в коде. – Slapout

+0

@slapout вы можете создавать почти все визуальные элементы управления или объекты непосредственно с помощью 'create', но также вам нужно прикрепить к окну или визуальному пользовательскому объекту с помощью OpenUserObject(), иначе почти все вызовы методов будут терпеть неудачу (так же как и' DirList() 'с непривязанным списком). Вы можете создать его динамически невидимым и прикрепить его к окну, но он не будет сильно отличаться от добавления невидимого списка в окно во время разработки. – Seki

+0

Можете ли вы динамически создать окно? Кажется, я помню, что весь код получил список файлов, размещенных внутри nvo. Но опять же моя память нечеткая. – Slapout

Смежные вопросы