Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list dir files in my listbox 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi,

Maybe I'm missing something but how can I get a list of all the files in a certain directory in a listbox ?

sorry, my brain is in 'summer' mode. :)

please help. thanks,

FOXUP!
 
In your command window type: HELP Listbox
And then when it comes up click on the ListBox Control Properties, Methods and Events

Then when that comes up look at the examples:
frmMyForm.lstListBox1.RowSourceType = 5 && Specifies an array
frmMyForm.lstListBox1.RowSource = 'gaMyListArray' && Array containing listbox items


That should help you understand what you can use for a Listbox.

You should be able to use the Array created by the ADIR() function as your Listbox RowSource.

You may also have to play with the Listbox's FirstElement property to get the correct array column displayed.

Good Luck,
JRB-Bldr
 
yup!

got it.

so I have this in my load event in my form

gnDbcnumber = ADIR(gaDatabase, '*.DAT') && Create array

and I've set up my rowsrouce and rowsourcetype and columncount and multiselect properly in my list box which gives me a list of the necessary file list in the list box and i'vm able to select more than 1 file in that list box.

what I want as an end-result is to concatenate all the 'selected text files from the list box" into 1 file name call allfilestg.txt


any help please,

thanks,
FOXUP!

 
To see which files are selected in a multi-select list, you loop through the Selected collection:

Code:
FOR nItem = 1 TO This.ListCount
   IF This.Selected[m.nItem]
      * The item is selected. Do something with it.
   ENDIF
ENDFOR

Tamar
 
I have this code:

strtofile(filetostr('B1104221.dat'),'B1104281.dat',.t.)

which will merge the 2 files but there are 2 problems with that simple line of code:
1- it doesn't keep the original files intact because it merges in atraight into the other
2 - I need to integrate that kinda from the list box list which was selected.

please help.

Thanks,
FOXUP!
 
what I want as an end-result is to concatenate all the 'selected text files from the list box" into 1 file name call allfilestg.txt

Personally I would have done the whole thing in a Grid using a Cursor to contain the list of filenames and to hold the SELECTED flags.

Then it would be very easy to get the Cursor's record content which have been SELECTED with a SCAN/ENDSCAN or with a separate SELECT SQL.

strtofile(filetostr('B1104221.dat'),'B1104281.dat',.t.)

Are you saying that you want to append one file to the other?
Code:
cFirstFileStr = FILETOSTR('B1104221.dat')
cSecondFileStr = FILETOSTR('B1104281.dat')
* --- Concatenate Text Data From Both Files ---
cNewFileStr = cFirstFileStr + CHR(13) + CHR(10) + cSecondFileStr
* --- Write to Output File ---
STRTOFILE(cNewFileStr,<output file name>)

Good Luck,
JRB-Bldr
 
Yes, correct. I want to append 1 file to the other (no CHR(13)+CHR(10). Basically just like the DOS command which is :

copy B1104221.dat+B1104281.dat allfilestg.txt


but instad of being only 2 files and want it to append all the files that I selectected in my listbox to a file called allfilestg.txt

any help please.

thanks,
FOXUP!
 
Foxup,

Do you want the files or the filenames concatated? If you want the filenames concatated than without a delimiter?

How about presenting a little example of requested output?

Our, at least mine, Crystal Ball does not seem to work today.

Regards,

Jockey(2)

 
"any help please." ????

I gave you what you need above.

If you do not want the CrLf between the individual file contents, then do what is shown, but leave out the + CHR(13) + CHR(10)

Code:
* --- Slight variation of above code for more files ---
cOutputFileStr = ''
SELECT MyFileList
SCAN FOR Selected
   * --- Get This File Contents Into String ---
   cThisFileStr = FILETOSTR(MyFileList.PathFile)
   * --- Concatenate To Output String
   cOutputFileStr = cOutputFileStr + cThisFileStr
ENDSCAN

* --- Output the total string to a file ---
cOutputFile = <fully pathed output file name>
=STRTOFILE(cOutputFileStr,cOutputFile)

Good Luck,
JRB-Bldr
 
* create an empty new file
StrToFile("","newfilename",.F.)

* append selected files to the new file
* eg For Each selectedfile in Selectedfiles &&array
* or SCAN..ENDSCAN
StrToFile(FileToStr(selectedfile),"newfilename",.t.)

You may really want to add chr(13)+chr(10). If we talk of csv or other data files they typically lack a CRLF after the last record, so simply appending the files wll then add the first record of a file to the last of the previous file. Take care.

Besides there is rowsourcetype=7 &&Files for a listbox of files.

Bye, Olaf.
 
Star to JRBBLDR. Thanks to everybody! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top