Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

for each dir

Hi All,

The problem iam facing with the script is .. it always takes the source files only from where the qvw is placed. Even changing the path to the different drive it does take the file from their..

All my files are placed in a folders like 2014.csv /2015.csv etc.. so the csv  file names are like file1-2014. so here file1-2014 needs to be into product. similarly I have file2-2014...etc

sub GetCSVFIleNames(Root)

    for each FoundFile in filelist( Root & '\*.csv')
   
    FoundFile = right('$(FoundFile)', 8);

Product:
LOAD

Customer Number,
    Customer Name,
     Product name] as [Product Name],
     [Product  number] as [Product Number]
    
FROM
['$(FoundFile)'\file1-'$(FoundFile)']
(txt, codepage is 1252, embedded labels, delimiter is ',', msq, header is 1 lines);


    next FoundFile

    for each SubDirectory in dirlist( Root & '\*' )

        call GetCSVFIleNames(SubDirectory)

    next SubDirectory

end sub

Call GetCSVFIleNames('H:/') ;

1 Solution

Accepted Solutions
sasiparupudi1
Master III
Master III

Great,glad that your problem is solved.

iMay I suggest that you close this thread by marking any helpful and a correct answer so that It can be helpful to other who might be looking for a similar solution?

Thanks

Sasi

View solution in original post

22 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

You are changing the iteration variable inside the loop.

              FoundFile = right('$(FoundFile)', 8);


This may cause unpredictable behaviour.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jonathandienst
Partner - Champion III
Partner - Champion III

Rather use the inner script like this:

For Each FoundFile in filelist( Root & '\*.csv')

  Product:

  LOAD

  Customer Number,

  Customer Name,

  Product name] as [Product Name],

  [Product  number] as [Product Number]

  FROM [$(FoundFile)]

  (txt, codepage is 1252, embedded labels, delimiter is ',', msq, header is 1 lines);

Next FoundFile

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
sasiparupudi1
Master III
Master III

Your function call parameter is wrong?

it should be Call GetCSVFIleNames('H:') ;

Not applicable
Author

Hi Jonanthan,

But their are multiple csv folders

for ex : 10020203.csv

100203232.csv

2014.csv

2013.csv

so iam only looking for folders like 2013.csv /2014.csv that's the reason I have limited the found file to look for 8 characters.

now as you said if I remove .. its taking most of the files.

Not applicable
Author

Hi Sridhar,

H: drive is good.. but still limitation of found file to 8 characters how can we achieve this?

sasiparupudi1
Master III
Master III

Try

sub GetCSVFIleNames(Root)

    for each FoundFile in filelist( Root & '\*.csv')
   
    FoundFile = right('$(FoundFile)', 8);

   //To get the file name

let vTmpFoundFile=SubField(FoundFile,'\',-1);

Product:
LOAD

Customer Number,
    Customer Name,
     Product name] as [Product Name],
     [Product  number] as [Product Number]
    
FROM
['$(FoundFile)']
(txt, codepage is 1252, embedded labels, delimiter is ',', msq, header is 1 lines);


    next FoundFile

    for each SubDirectory in dirlist( Root & '\*' )

        call GetCSVFIleNames(SubDirectory)

    next SubDirectory

end sub

Call GetCSVFIleNames('H:') ;

hth

Sasi

Not applicable
Author

hi Sridhar,

it is loading but how do I know it is take from file1-2014 only?

Not applicable
Author

hi sasi,

for ex

my requirement was to

['$(FoundFile)'\file1-'$(FoundFile)']  -file into Product:

but indeed it is stopping exactly after loading into product.. file 2 it is saying not found..

sasiparupudi1
Master III
Master III

Hi Benny

Why dont you store the file name into a field in your table so that you will know which file the data has come from?

sub GetCSVFIleNames(Root)

    for each FoundFile in filelist( Root & '\*.csv')
   
    FoundFile = right('$(FoundFile)', 8);

   //To get the file name

let vTmpFoundFile=SubField(FoundFile,'\',-1);

Product:
LOAD

Customer Number,
    Customer Name,
     Product name] as [Product Name],
     [Product  number] as [Product Number]
    '$(FoundFile)' as SourceFile
FROM
['$(FoundFile)']
(txt, codepage is 1252, embedded labels, delimiter is ',', msq, header is 1 lines);


    next FoundFile

    for each SubDirectory in dirlist( Root & '\*' )

        call GetCSVFIleNames(SubDirectory)

    next SubDirectory

end sub

Call GetCSVFIleNames('H:') ;

hth

Sasi