How to make a list of files in a folder directory

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
MrBlack
Participant
Posts: 125
Joined: Wed Aug 08, 2012 8:57 am

How to make a list of files in a folder directory

Post by MrBlack »

Here's my latest challenge, scan a folder and make a list of the files for a particular file type. For example a make a list of all the *.dbf files in a particular folder. Because once I have that list I'm going to loop through and make an ODBC connection to that file and extract the data that I want. I will never know how many files are going to be in the folder and all I need is the file name. Bonus if I can use the date modified of the file to determine if I should add it to the list since the last run time of my job.

I know there is a Folder Stage but I haven't ever used it but I believe it takes two columns: file name, file data. Can that stage do a recursive search if I also need to scan sub folders?

Another way I thought of doing it is writing a linux script that data stage calls and have the OS do the work of making a CSV of file names for data stage to use.

Does anyone have any insight or pointers?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The Folder stage doesn't support sub-folders. Regardless, in my opinion it is best to stick with the UNIX command approach in a User Variables Activity stage feeding a Start/End Loop sequence job. Your modification time filter may need to be post-list as I don't recall a way to directly compare it to a supplied timestamp while generating the list, only if it is X days old... ala 'find' for example.

There may very well be a way, it's just not coming to me at this exact moment. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How about using a Sequential File stage with a find command as the Filter? The find command probably has all the options you'll need.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
MrBlack
Participant
Posts: 125
Joined: Wed Aug 08, 2012 8:57 am

Post by MrBlack »

How do I execute a Unix command from within a UserVariable stage? And the unix command I would call, is it just a combination of the ls command?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You would execute your ls command in a command activity, then parse and interpret the output of the ls command in a user activity stage.
Post Reply