Hi,
How can I pull folder names from a directory? I do not want the subfolders or files names
I also want the folder names even if they do not contain a file.
Thanks.
You can do it by parsing the folder names from the results of the directory tool. This workflow is one way to do it, although it isn't dynamic.
To make it dynamic you could turn it into a macro, where the input to the directory tool also changes the RegEx tool
@FinnCharlton I was thinking along these lines. However, if you have a folder in your directory which doesn't contain files, the directory tool will not output this particular folder as a result (using this workflow approach). Thus, this won't display all folders as requested.
It would be nice to see something where it display the folders and if there isn't any files, it displays Null under 'FileName'.
thanks it works.. would there be any scenario where this wouldnt get all folder names? It seems like I am not getting all of them. Only 50/200 are being returned..
@wonka1234 Do the folders, that are not being returned, contain files?
If you need folders without files then I don't think the directory tool can help you. In this case you'll need to use the "Run Command" tool to display all the folders in a directory. Using the dir command along with the d attribute will just show you folders without files or subfolders. There is plenty of online material around this - here is a decent intro to the Run Command tool:
https://carlscholl.com/2022/02/21/how-to-use-alteryx-and-run-command-functionality-to-batch-copy-a-template-file/
And here is the documentation for the dir commnad:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/dir
Hi @wonka1234
See attached. Failing this, you can use the Run tool and config to use a .bat to list folders
Please find attached solution, May be it will help you to find you answer. Just run the app and select the folder location and run.
Use this updated solution, ignore last one.
@wonka1234 I think I got it now! Just insert your link into the Text Input file (replace the current one). Press 'Run'. Click on the output anchor 1, all folders should be displayed even if they are empty! This doesn't contain the subdirectory folders though. Just all folders within the current folder.
Do you have a script to perform this? because I tried but seems the host can't connect this way when a directory is outlined. Can you attach an example workflow of this working?
@BS_THE_ANALYST very nice
@BS_THE_ANALYST
would you be able to share the python? I cannot view it in jupyter notebook.
Have you checked my solution? You have to run as an App and provide path.
@wonka1234 code is underneath the picture below. Hopefully it works for you. Just copy as paste it in the Jupter Notebook.
from ayx import Package#Package.installPackages(['pandas','numpy'])from ayx import Alteryximport osimport numpy as npimport pandas as pd
var1 = Alteryx.read("#1")a = var1.iloc[0,0]link = a.replace("\\","/")link# # Get list of folders in file pathfolder_list = os.listdir(link)
[folder for folder in folder_list if folder.find(".") == -1 ]
df = pd.DataFrame(data = [folder for folder in folder_list if folder.find(".") == -1 ], columns=["Folders"])Alteryx.write(df, 1)