Board index » cppbuilder » List of files
|
sam
CBuilder Developer |
|
sam
CBuilder Developer |
List of files2004-04-21 08:43:31 PM cppbuilder89 How is-it possible to do: dir *.txt and get the files list in a buffer ? Sam |
| JD
CBuilder Developer |
2004-04-21 08:58:33 PM
Re:List of files
"sam" < XXXX@XXXXX.COM >wrote:
QuoteHow is-it possible to do: to load the data. Otherwise you're going to have to pipe the data directly into a control: void __fastcall TForm1::Button1Click(TObject *Sender) { //create pipe for the console stdout SECURITY_ATTRIBUTES sa; ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES)); sa.nLength=sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle=true; sa.lpSecurityDescriptor=NULL; HANDLE ReadPipeHandle; HANDLE WritePipeHandle; // not used here if(!CreatePipe(&ReadPipeHandle,&WritePipeHandle,&sa,0)) RaiseLastWin32Error(); //Create a Console STARTUPINFO si; ZeroMemory(&si,sizeof(STARTUPINFO)); si.cb=sizeof(STARTUPINFO); si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; si.wShowWindow=SW_HIDE; si.hStdOutput=WritePipeHandle; si.hStdError=WritePipeHandle; PROCESS_INFORMATION pi; ZeroMemory(&pi,sizeof(PROCESS_INFORMATION)); if(!CreateProcess("the dos command or your Program.exe",NULL,NULL,NULL,true,0,NULL,NULL,&si,&pi)) RaiseLastWin32Error(); //Read from pipe char Data[1024]; for (;;) { DWORD BytesRead; DWORD TotalBytes; DWORD BytesLeft; //Check for the presence of data in the pipe if(!PeekNamedPipe(ReadPipeHandle,Data,sizeof(Data),&BytesRead, &TotalBytes,&BytesLeft))RaiseLastWin32Error(); //If there is bytes, read them if(BytesRead) { if(!ReadFile(ReadPipeHandle,Data,sizeof(Data)-1,&BytesRead,NULL)) RaiseLastWin32Error(); Data[BytesRead]='\0'; Memo1->Lines->Add(AnsiString(Data)); } else { //Is the console app terminated? if(WaitForSingleObject(pi.hProcess,0)==WAIT_OBJECT_0)break; } } CloseHandle(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(ReadPipeHandle); CloseHandle(WritePipeHandle); } ~ JD |
| Remy Lebeau (TeamB)
CBuilder Developer |
2004-04-22 01:14:09 AM
Re:List of files
"sam" < XXXX@XXXXX.COM >wrote in message
QuoteHow is-it possible to do: TSearchRec sr; if( FindFirst("c:\\path to search\\*.txt", faAnyFile, sr) == 0 ) { do { FileNames->Append(sr.Name); } while( FindNext(sr) == 0 ); FindClose(sr); } // use FileNames as needed... delete FileNames; Gambit {smallsort} |
| JD
CBuilder Developer |
2004-04-22 03:16:19 AM
Re:List of files
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
QuoteUse the VCL's FindFirst() and FindNext() functions, |
| Michel Leunen
CBuilder Developer |
2004-04-22 03:17:01 AM
Re:List of files
JD wrote:
QuoteOtherwise you're going to have to pipe the data directly into JD, you're not a nice guy! Michel -- ---------------------------------------- Michel Leunen mailto: see my homepage. C++Builder, C++BuilderX, BCC5.5.1 Web site: www.leunen.com/ ---------------------------------------- |
| Hans Galema
CBuilder Developer |
2004-04-22 05:04:02 AM
Re:List of files
Michel Leunen wrote:
QuoteCode coming straight from my site without mentioning it. QuoteJD, you're not a nice guy! For me it takes a bit more to consider JD not a nice guy. Hans. |
| Michel Leunen
CBuilder Developer |
2004-04-23 03:42:38 AM
Re:List of files
Hans Galema wrote:
QuoteFor me it takes a bit more to consider JD not a nice guy. Michel -- ---------------------------------------- Michel Leunen mailto: see my homepage. C++Builder, C++BuilderX, BCC5.5.1 Web site: www.leunen.com/ ---------------------------------------- |
| JD
CBuilder Developer |
2004-04-23 04:57:20 AM
Re:List of files
Michel Leunen < XXXX@XXXXX.COM >wrote:
QuoteCode coming straight from my site without mentioning it. seggregate code collected from newsgroups such as this one and code collected from other sites. Do you think that it's possible that you may have posted that block of code here before? Beside the fact that I've never visited your site, I don't post code from other sites because of copyrite issues. At first I saved salutations with the samples but the collection grew and it's just one more thing to add and maintain with the db. So .... Allow me to appoligize to you and everyone else who's samples I have posted and will post without credits. ~ JD |
| Michel Leunen
CBuilder Developer |
2004-04-24 03:43:39 AM
Re:List of files
JD wrote:
QuoteDo you think that it's possible that you may have posted that QuoteBeside the fact that I've never visited your site, QuoteAllow me to appoligize to you and everyone else who's samples code even if giving credit would have been appreciated. Appreciated but not necessary. And I understand that knowing where a code snippet is coming from is hard and not always doable. Sorry for having been so harsh. Michel -- ---------------------------------------- Michel Leunen mailto: see my homepage. C++Builder, C++BuilderX, BCC5.5.1 Web site: www.leunen.com/ ---------------------------------------- |
