Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to get results of DIR command into AlterYX

bsharbo
11 - Bolide

Hello everyone. I have a requirement that I need to be able to look at a given directory, and get a list of all of the files + folders in that directory.

 

Unfortunately the Directory command tool only shows files (if anyone knows how to get it to show just directories please let me know!).

 

Because of this limitation I was planning on using a run command to simply produce the outputs of a given directory command. However I cannot seem to get alteryx to 'read back' the output of the directory command.

 

Attached is my current example workflow (very simple workflow to show an example of the problem i'm having).  Does anyone have any ideas on how to get this function to work correctly?

 

Thanks!

10 REPLIES 10
jdunkerley79
ACE Emeritus
ACE Emeritus

Have attached a RunCommand example getting a directory list.

s_pichaipillai
12 - Quasar

what about this Macro using Directory tool?

this will result below details

Dir.PNG

bsharbo
11 - Bolide

Bunkerly to the rescue again!  Okay so as always I have a few questions for you here :-) It looks like are building the commands for a .bat file and somehow storing it SOMEWHERE.... and then the command line is using the pushd command to change the directory to the .bat file you just made, then running the dir command, and then using the popd command to get back to the original directory...

 

You union statement produces the following commands...

 

pushd "%~dp0"

dir /B "I:\Projects\Brandon\AlterYX Workflows" > dirlist.txt

popd

 

 

In my past experience with bat files, if you had a batfile in a directory called c:\mybatfiles\MyBat.bat  and you input that variable %~dp0, it would actually resolve too c:\mybatfiles  (the full directory of the bat file location).  However I can't see where you are making a bat file in your code so I am bit confused :-)

 

I appreciate your help again as always!

 

 

 

Thanks for the additional info!

jdunkerley79
ACE Emeritus
ACE Emeritus

The batch file is written within the RunCommand tool:

writeBatch.jpg

 

This is then executed:

execCommand.jpg

 

And finally the results are read as a flat file:

readOutput.jpg

 

This is far and away my favourite trick with the Run Command tool as you can pretty much do anything this way (in a past life used it to access financial data for analytics)

bsharbo
11 - Bolide

Oh my god I just realized what you were doing with the %temp% directory.

 

This is a GENIUS solution I am going to abuse this all over the place :-)

 

Thank you very much for your help!

bsharbo
11 - Bolide

One more follow up question for you!

 

Your method is awesome and extremely helpful, but it will generate quite a bit of temp folder paths that aren't needed. Do you generally just run a clean up tool on your server on some schedule to clean out your temp folder?

 

Thanks!

rdoptis
11 - Bolide

Individual %Temp% directories are created for each run, and Alteryx cleans them up automatically at the end of your session.

jdunkerley79
ACE Emeritus
ACE Emeritus

As @rdoptis says the temp dir gets cleaned up, as long as you dont create sub folders I think.

 

Think only cleaned complete when you close Alteryx but might be more frequent

vinay4444
7 - Meteor

Hi thanks for the solution how do i take the output into a select tool as i need to get just the latest foldername (not filenames or old folders)

 

thanks

Labels