Expand my Community achievements bar.

SOLVED

List subfolders of an SFTP location in campaign javascript activity

Avatar

Level 2

Hi All,

I'm currently working on loading some data into Adobe Campaign Classic V7 which has been exported from a dataset in AEP. As AEP creates a new subfolder each time it exports an incremental file I'm finding it hard to automate the loading of these files in ACM due to not having a consistent location the files are placed.


The files exported from AEP Dataflow activity are placed directly on our Adobe Campaign SFTP. I would like to understand how I can find those files easily in campaign SFTP for loading.
I have Javascript already that lists the files present within a particular ACM SFTP Location, but would want to amend the code to list the folders present within that ACM location. 

The code used to list files in a location is below. How can I amend this to list the sub-folders present in the provided location. I've tried various different codes and objects and each of them seem to not be available for use in ACM Javascript
---------------Code Start--------------------

// SFTP file directory
var providerDirectories =  "/sftp/incoming/to_campaign/from_aep/";

var d = new File(providerDirectories);
var fileList = d.list("*.*",true);

// Counting number of files
logInfo ("fileList Count: " + fileList.length);

var i=0;
for each(var filename in fileList)
{
i=i+1;
logInfo ("file "+[i]+": " + filename.name);
}

---------------Code End---------------------

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi ALangridge,

I was able to get a piece of code from another colleague which does the job I needed.

The code is the below:

--------file operation on sftp from WF-----

 

var folder = new File('//home//');//change your dir here
logInfo('1')
if(!folder.isDirectory)
{
logInfo('not a dir');}
logInfo('2')
var sortListAlphabetically=true;
var ignoreCase = false;

 

for each(var subfolder in folder.list('*',sortListAlphabetically,ignoreCase))
{//change the directory filter here
logInfo('3')
logInfo('Found subfolder',subfolder.path);
if(!subfolder.isDirectory)
{continue;}
for each(var file in subfolder.list('*',sortListAlphabetically,ignoreCase))
{//change the file filter here
if(!file.isFile)
{
continue;}
logInfo('4')
logInfo('-found file:',file.fullName);
//file.remove();//uncomment to delete files
}
}

 

Thanks for looking into it though, 

Appreciate the suggestions.

Ash

View solution in original post

3 Replies

Avatar

Level 4

Bad news: I don't know of any way to work with directories via the File() class and methods. 


Good news: When previously using AEP, our exports were all going to the same folder - it would just have a date stamp at the end of the name. 

Annoying news: We're no longer using AEP, so I can't confirm specifically how this was achieved. But if you chase this up with the AEP team, you may end up with everything in a single file location!

 

From there a basic amendment to your code to check .lastModified and then maybe a .copyTo() and .remove() to move and archive the processed files will have you all good. 

Avatar

Correct answer by
Level 2

Hi ALangridge,

I was able to get a piece of code from another colleague which does the job I needed.

The code is the below:

--------file operation on sftp from WF-----

 

var folder = new File('//home//');//change your dir here
logInfo('1')
if(!folder.isDirectory)
{
logInfo('not a dir');}
logInfo('2')
var sortListAlphabetically=true;
var ignoreCase = false;

 

for each(var subfolder in folder.list('*',sortListAlphabetically,ignoreCase))
{//change the directory filter here
logInfo('3')
logInfo('Found subfolder',subfolder.path);
if(!subfolder.isDirectory)
{continue;}
for each(var file in subfolder.list('*',sortListAlphabetically,ignoreCase))
{//change the file filter here
if(!file.isFile)
{
continue;}
logInfo('4')
logInfo('-found file:',file.fullName);
//file.remove();//uncomment to delete files
}
}

 

Thanks for looking into it though, 

Appreciate the suggestions.

Ash

Avatar

Level 4

Oh gotcha! I just realised I was doing the same thing as you in your original code, using a "*.*" mask - which of course would ignore folders haha.