comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Writing each filename into new line of text file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Writing each filename into new line of text file [message #91060] Fri, 29 May 2015 05:48 Go to next message
Kai Heckel is currently offline  Kai Heckel
Messages: 51
Registered: April 2015
Member
Hey!

I'd like to list my files and write them into a text file. Each filename should be in a separate line....
Shouldn't be to hard ;)

This is what I have:

PRO test
cd, 'Path of my files'
files_all = FILE_SEARCH()
openw,lun1,'fileinfo.txt', /get_lun
printf, lun1, files_all, FORMAT='(A)'
close, lun1
free_lun,lun1
END

I couldn't find any suitable command till now...

Thanks!
Re: Writing each filename into new line of text file [message #91063 is a reply to message #91060] Fri, 29 May 2015 11:19 Go to previous messageGo to next message
Nikola is currently offline  Nikola
Messages: 53
Registered: November 2009
Member
This should suffice;

PRO test
cd, 'Path of my files'
files_all = FILE_SEARCH()
openw,lun1,'fileinfo.txt', /get_lun
FOR i = 0, N_ELEMENTS(files_all) DO $
printf, lun1, files_all[i]
free_lun,lun1
END

Try

help, files_all

it's an array
Re: Writing each filename into new line of text file [message #91065 is a reply to message #91060] Fri, 29 May 2015 13:43 Go to previous messageGo to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
On Friday, 29 May 2015 05:48:43 UTC-7, Kai Heckel wrote:
> Hey!
>
> I'd like to list my files and write them into a text file. Each filename should be in a separate line....
> Shouldn't be to hard ;)
>
> This is what I have:
>
> PRO test
> cd, 'Path of my files'
> files_all = FILE_SEARCH()
> openw,lun1,'fileinfo.txt', /get_lun
> printf, lun1, files_all, FORMAT='(A)'
> close, lun1
> free_lun,lun1
> END
>
> I couldn't find any suitable command till now...
>
> Thanks!

As we often ask around here, "in what way is this not working for you?". When I run this, it does write every filename on a separate line, as expected. It also seems to be listing contained folders... is that the problem? If so, use this instead:

files_all = FILE_SEARCH(/TEST_REGULAR)

Bonus: if you're going to do "free_lun", you don't have to do "close"!

Cheers,
-Dick

Dick Jackson Software Consulting Inc.
Victoria, BC, Canada --- http://www.d-jackson.com
Re: Writing each filename into new line of text file [message #91070 is a reply to message #91065] Mon, 01 June 2015 00:24 Go to previous messageGo to next message
Kai Heckel is currently offline  Kai Heckel
Messages: 51
Registered: April 2015
Member
Am Freitag, 29. Mai 2015 22:43:57 UTC+2 schrieb Dick Jackson:
> On Friday, 29 May 2015 05:48:43 UTC-7, Kai Heckel wrote:
>> Hey!
>>
>> I'd like to list my files and write them into a text file. Each filename should be in a separate line....
>> Shouldn't be to hard ;)
>>
>> This is what I have:
>>
>> PRO test
>> cd, 'Path of my files'
>> files_all = FILE_SEARCH()
>> openw,lun1,'fileinfo.txt', /get_lun
>> printf, lun1, files_all, FORMAT='(A)'
>> close, lun1
>> free_lun,lun1
>> END
>>
>> I couldn't find any suitable command till now...
>>
>> Thanks!
>
> As we often ask around here, "in what way is this not working for you?". When I run this, it does write every filename on a separate line, as expected. It also seems to be listing contained folders... is that the problem? If so, use this instead:
>
> files_all = FILE_SEARCH(/TEST_REGULAR)
>
> Bonus: if you're going to do "free_lun", you don't have to do "close"!
>
> Cheers,
> -Dick
>
> Dick Jackson Software Consulting Inc.
> Victoria, BC, Canada --- http://www.d-jackson.com


Thank you very much for your solutions!

@ Nikola:
If I try your version it prints my datasets into 3 columns for some reason...

@ Dick:
"/TEST_REGULAR" returns an empty string (not an array as needed)

I assume that it should be possible to reduce the number of columns in Nikolas version in some way.....isn't it?

Thanks everyone!
Re: Writing each filename into new line of text file [message #91071 is a reply to message #91070] Mon, 01 June 2015 00:30 Go to previous messageGo to next message
Kai Heckel is currently offline  Kai Heckel
Messages: 51
Registered: April 2015
Member
Am Montag, 1. Juni 2015 09:24:23 UTC+2 schrieb Kai Heckel:
> Am Freitag, 29. Mai 2015 22:43:57 UTC+2 schrieb Dick Jackson:
>> On Friday, 29 May 2015 05:48:43 UTC-7, Kai Heckel wrote:
>>> Hey!
>>>
>>> I'd like to list my files and write them into a text file. Each filename should be in a separate line....
>>> Shouldn't be to hard ;)
>>>
>>> This is what I have:
>>>
>>> PRO test
>>> cd, 'Path of my files'
>>> files_all = FILE_SEARCH()
>>> openw,lun1,'fileinfo.txt', /get_lun
>>> printf, lun1, files_all, FORMAT='(A)'
>>> close, lun1
>>> free_lun,lun1
>>> END
>>>
>>> I couldn't find any suitable command till now...
>>>
>>> Thanks!
>>
>> As we often ask around here, "in what way is this not working for you?". When I run this, it does write every filename on a separate line, as expected. It also seems to be listing contained folders... is that the problem? If so, use this instead:
>>
>> files_all = FILE_SEARCH(/TEST_REGULAR)
>>
>> Bonus: if you're going to do "free_lun", you don't have to do "close"!
>>
>> Cheers,
>> -Dick
>>
>> Dick Jackson Software Consulting Inc.
>> Victoria, BC, Canada --- http://www.d-jackson.com
>
>
> Thank you very much for your solutions!
>
> @ Nikola:
> If I try your version it prints my datasets into 3 columns for some reason...
>
> @ Dick:
> "/TEST_REGULAR" returns an empty string (not an array as needed)
>
> I assume that it should be possible to reduce the number of columns in Nikolas version in some way.....isn't it?
>
> Thanks everyone!

Hey! Me again ;)

I found the solution it is, as always, surprisingly easy!
Replacing the format-argument "A" with "A0" worked out as desired.
Now every file is written to a new line!

Thanks for your help!
Re: Writing each filename into new line of text file [message #91072 is a reply to message #91071] Mon, 01 June 2015 02:20 Go to previous messageGo to next message
Kai Heckel is currently offline  Kai Heckel
Messages: 51
Registered: April 2015
Member
Am Montag, 1. Juni 2015 09:30:26 UTC+2 schrieb Kai Heckel:
> Am Montag, 1. Juni 2015 09:24:23 UTC+2 schrieb Kai Heckel:
>> Am Freitag, 29. Mai 2015 22:43:57 UTC+2 schrieb Dick Jackson:
>>> On Friday, 29 May 2015 05:48:43 UTC-7, Kai Heckel wrote:
>>>> Hey!
>>>>
>>>> I'd like to list my files and write them into a text file. Each filename should be in a separate line....
>>>> Shouldn't be to hard ;)
>>>>
>>>> This is what I have:
>>>>
>>>> PRO test
>>>> cd, 'Path of my files'
>>>> files_all = FILE_SEARCH()
>>>> openw,lun1,'fileinfo.txt', /get_lun
>>>> printf, lun1, files_all, FORMAT='(A)'
>>>> close, lun1
>>>> free_lun,lun1
>>>> END
>>>>
>>>> I couldn't find any suitable command till now...
>>>>
>>>> Thanks!
>>>
>>> As we often ask around here, "in what way is this not working for you?". When I run this, it does write every filename on a separate line, as expected. It also seems to be listing contained folders... is that the problem? If so, use this instead:
>>>
>>> files_all = FILE_SEARCH(/TEST_REGULAR)
>>>
>>> Bonus: if you're going to do "free_lun", you don't have to do "close"!
>>>
>>> Cheers,
>>> -Dick
>>>
>>> Dick Jackson Software Consulting Inc.
>>> Victoria, BC, Canada --- http://www.d-jackson.com
>>
>>
>> Thank you very much for your solutions!
>>
>> @ Nikola:
>> If I try your version it prints my datasets into 3 columns for some reason...
>>
>> @ Dick:
>> "/TEST_REGULAR" returns an empty string (not an array as needed)
>>
>> I assume that it should be possible to reduce the number of columns in Nikolas version in some way.....isn't it?
>>
>> Thanks everyone!
>
> Hey! Me again ;)
>
> I found the solution it is, as always, surprisingly easy!
> Replacing the format-argument "A" with "A0" worked out as desired.
> Now every file is written to a new line!
>
> Thanks for your help!

Hey!

Another question just came up. In order to control my processing process with a lot of files I'd like to create two lists (txt.'s). One list contains the properly processed (ok_list) and one list the corrupt files(error_list). Based on an exitcode from my processor I'd like to write the name of the currently processed file into the correct list.

The only problem I have here is that e.g. if 2 files are correctly processed the first line of my ok_list should not be overwritten. How do I manage to do that?
Re: Writing each filename into new line of text file [message #91073 is a reply to message #91072] Mon, 01 June 2015 05:06 Go to previous messageGo to next message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den måndag 1 juni 2015 kl. 11:20:38 UTC+2 skrev Kai Heckel:
> Am Montag, 1. Juni 2015 09:30:26 UTC+2 schrieb Kai Heckel:
>> Am Montag, 1. Juni 2015 09:24:23 UTC+2 schrieb Kai Heckel:
>>> Am Freitag, 29. Mai 2015 22:43:57 UTC+2 schrieb Dick Jackson:
>>>> On Friday, 29 May 2015 05:48:43 UTC-7, Kai Heckel wrote:
>>>> > Hey!
>>>> >
>>>> > I'd like to list my files and write them into a text file. Each filename should be in a separate line....
>>>> > Shouldn't be to hard ;)
>>>> >
>>>> > This is what I have:
>>>> >
>>>> > PRO test
>>>> > cd, 'Path of my files'
>>>> > files_all = FILE_SEARCH()
>>>> > openw,lun1,'fileinfo.txt', /get_lun
>>>> > printf, lun1, files_all, FORMAT='(A)'
>>>> > close, lun1
>>>> > free_lun,lun1
>>>> > END
>>>> >
>>>> > I couldn't find any suitable command till now...
>>>> >
>>>> > Thanks!
>>>>
>>>> As we often ask around here, "in what way is this not working for you?". When I run this, it does write every filename on a separate line, as expected. It also seems to be listing contained folders... is that the problem? If so, use this instead:
>>>>
>>>> files_all = FILE_SEARCH(/TEST_REGULAR)
>>>>
>>>> Bonus: if you're going to do "free_lun", you don't have to do "close"!
>>>>
>>>> Cheers,
>>>> -Dick
>>>>
>>>> Dick Jackson Software Consulting Inc.
>>>> Victoria, BC, Canada --- http://www.d-jackson.com
>>>
>>>
>>> Thank you very much for your solutions!
>>>
>>> @ Nikola:
>>> If I try your version it prints my datasets into 3 columns for some reason...
>>>
>>> @ Dick:
>>> "/TEST_REGULAR" returns an empty string (not an array as needed)
>>>
>>> I assume that it should be possible to reduce the number of columns in Nikolas version in some way.....isn't it?
>>>
>>> Thanks everyone!
>>
>> Hey! Me again ;)
>>
>> I found the solution it is, as always, surprisingly easy!
>> Replacing the format-argument "A" with "A0" worked out as desired.
>> Now every file is written to a new line!
>>
>> Thanks for your help!
>
> Hey!
>
> Another question just came up. In order to control my processing process with a lot of files I'd like to create two lists (txt.'s). One list contains the properly processed (ok_list) and one list the corrupt files(error_list). Based on an exitcode from my processor I'd like to write the name of the currently processed file into the correct list.
>
> The only problem I have here is that e.g. if 2 files are correctly processed the first line of my ok_list should not be overwritten. How do I manage to do that?

Read the manual for the OPENW command and find the APPEND keyword?
Re: Writing each filename into new line of text file [message #91074 is a reply to message #91073] Mon, 01 June 2015 06:19 Go to previous message
Kai Heckel is currently offline  Kai Heckel
Messages: 51
Registered: April 2015
Member
Am Montag, 1. Juni 2015 14:06:29 UTC+2 schrieb Mats Löfdahl:
> Den måndag 1 juni 2015 kl. 11:20:38 UTC+2 skrev Kai Heckel:
>> Am Montag, 1. Juni 2015 09:30:26 UTC+2 schrieb Kai Heckel:
>>> Am Montag, 1. Juni 2015 09:24:23 UTC+2 schrieb Kai Heckel:
>>>> Am Freitag, 29. Mai 2015 22:43:57 UTC+2 schrieb Dick Jackson:
>>>> > On Friday, 29 May 2015 05:48:43 UTC-7, Kai Heckel wrote:
>>>> > > Hey!
>>>> > >
>>>> > > I'd like to list my files and write them into a text file. Each filename should be in a separate line....
>>>> > > Shouldn't be to hard ;)
>>>> > >
>>>> > > This is what I have:
>>>> > >
>>>> > > PRO test
>>>> > > cd, 'Path of my files'
>>>> > > files_all = FILE_SEARCH()
>>>> > > openw,lun1,'fileinfo.txt', /get_lun
>>>> > > printf, lun1, files_all, FORMAT='(A)'
>>>> > > close, lun1
>>>> > > free_lun,lun1
>>>> > > END
>>>> > >
>>>> > > I couldn't find any suitable command till now...
>>>> > >
>>>> > > Thanks!
>>>> >
>>>> > As we often ask around here, "in what way is this not working for you?". When I run this, it does write every filename on a separate line, as expected. It also seems to be listing contained folders... is that the problem? If so, use this instead:
>>>> >
>>>> > files_all = FILE_SEARCH(/TEST_REGULAR)
>>>> >
>>>> > Bonus: if you're going to do "free_lun", you don't have to do "close"!
>>>> >
>>>> > Cheers,
>>>> > -Dick
>>>> >
>>>> > Dick Jackson Software Consulting Inc.
>>>> > Victoria, BC, Canada --- http://www.d-jackson.com
>>>>
>>>>
>>>> Thank you very much for your solutions!
>>>>
>>>> @ Nikola:
>>>> If I try your version it prints my datasets into 3 columns for some reason...
>>>>
>>>> @ Dick:
>>>> "/TEST_REGULAR" returns an empty string (not an array as needed)
>>>>
>>>> I assume that it should be possible to reduce the number of columns in Nikolas version in some way.....isn't it?
>>>>
>>>> Thanks everyone!
>>>
>>> Hey! Me again ;)
>>>
>>> I found the solution it is, as always, surprisingly easy!
>>> Replacing the format-argument "A" with "A0" worked out as desired.
>>> Now every file is written to a new line!
>>>
>>> Thanks for your help!
>>
>> Hey!
>>
>> Another question just came up. In order to control my processing process with a lot of files I'd like to create two lists (txt.'s). One list contains the properly processed (ok_list) and one list the corrupt files(error_list). Based on an exitcode from my processor I'd like to write the name of the currently processed file into the correct list.
>>
>> The only problem I have here is that e.g. if 2 files are correctly processed the first line of my ok_list should not be overwritten. How do I manage to do that?
>
> Read the manual for the OPENW command and find the APPEND keyword?

Yep, thanks. Reading the lines into a string array and then transferring it back to the original file seemed to be the most simple way to do it
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: NEWTON: Roundoff problem in lnsrch_d
Next Topic: Confused about image dimensions

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:13:41 PDT 2025

Total time taken to generate the page: 0.00694 seconds