How to create a folder, if its not existing already
@vencric Not sure it is really an alteryx question. 😂
Hi Qiu, Thanks for the solution,. I m facing below error
Also the folder will vary depending on the name, coming from formula tool dynamically
@vencric It did not happen to me as for the error, are running the flow from a remote location?I am sure your have the %temp% as environment variable.For the path, we can of course blend into the formula.
No.. Not running from remote location and also included %TEMP%
hi @Qiu , i am able to create folder in my local machine.... but when i'm trying to create in sharedrive, im getting this error
Hi @vencric ,
You can drag a python tool and add the following Python code:
from ayx import Alteryxfrom os import makedirsfrom pandas import DataFramedf=Alteryx.read("#1")path=df["path"][0]
try:makedirs(path)except OSError:message_log = {"MessageLog" : "Failed creation of the directory " + path,"FolderCreated" : 0,"Path":path}
else:message_log = {"MessageLog" : "Successfully created the directory: "+ path,"FolderCreated" : 1,"Path" :path}output_df = DataFrame(message_log,index=[0])
Alteryx.write(output_df,1)
Hi @Pravallika20 ... i faced error while runinng it... is it possible to create a folder in network drive
You can create the folder in network drive. Can u tell me the error u are facing
SUCCESS: reading input data "#1"
---------------------------------------------------------------------------KeyError Traceback (most recent call last)c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2656 try:-> 2657 return self._engine.get_loc(key) 2658 except KeyError:pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()KeyError: 'networkpath'During handling of the above exception, another exception occurred:KeyError Traceback (most recent call last)<ipython-input-2-46de07459b84> in <module> 3 from pandas import DataFrame 4 df=Alteryx.read("#1")----> 5 path=df["network Path"][0] 6 7 try:c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\site-packages\pandas\core\frame.py in __getitem__(self, key) 2925 if self.columns.nlevels > 1: 2926 return self._getitem_multilevel(key)-> 2927 indexer = self.columns.get_loc(key) 2928 if is_integer(indexer): 2929 indexer = [indexer]c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance) 2657 return self._engine.get_loc(key) 2658 except KeyError:-> 2659 return self._engine.get_loc(self._maybe_cast_indexer(key)) 2660 indexer = self.get_indexer([key], method=method, tolerance=tolerance) 2661 if indexer.ndim > 1 or indexer.size > 1:pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()KeyError: 'NetworkPath'
send me your workflow
Hi @atcodedog05 , how to check if 5C, is present in LC5A.. if i use REGEX_Countmatches, it showing true, because it has C5, instead
Hi @vencric
You can use contains function like Contains([Field1], "5C"). And can you share your regex function as far I know regex should also work might need some tweaking.
Hope this helps : )
Hi @atcodedog05 this is the function i used..
REGEX_CountMatches([Part Prefix], "B5|1M|C5|2C|3U|Z8|Z9|J9|K9").. part prefix is the column where it wil have many words, like
DSLC5B
ESLC5B
ILLC5B
LB5B
Here it should return True condition only for LB5B.. where its returning true for all the above records
Something below would be better and easy to maintain as a list.
Thanks @atcodedog05 .But the list will be changed dynamically based on the input.. thats why i used REGEX_CountMatches
Here is the Regex way
(:?) is used to create an unmarked group which checks the input for the chars in the list.
Hi @atcodedog05 how to concatenate values in same rows till blank value is found
hi @fharper how to concatenate values in same rows till blank value is found
@vencric , you should not embed multiple problems within same thread. It becomes impossible for others to follow and to search for answers.
the info in this thread should be specific to the original issue "How to create a folder, if its not existing already".
about 2/3rds of the way through the second page of responses the discussion jumps track to a different problem with discussion around using regex and other things to determine and respond to a condition. At least it seems to be a leap to a different subject.
Also we do not see anything marked as a solution...so was your original problem of dynamically creating a folder when needed resolved and if so then please mark that reply as the answer so others with the same problem can find it.
I suggest creating a new thread for the other issue so it can be searched and a solution, assuming there is one, can be identified by others searching. you might ask one of the moderators to do this for you. I know they used to do that when they notice multiple issues in a single thread.
@vencric "how to concatenate values in same rows till blank value is found" should be title or subject of a new thread. and in regards to that clarify if this is concatenating multiple columns/fields on a row or multiple substrings within a field, which is really more a parsing question.
The statement is generic enough it could be taken either way or both which can lead to very different solutions.
Provide as much detail as possible so others who seek to help will have minimal questions and can quickly provide good ideas.
How to concatenate value in same row, till blank value is found. Ex.
@fharper @atcodedog05
Input:
Level Prefix Base Concat
0 JH 1000
1 KB 1001 KB-1001
2 BC 1002 BC-1002
1 CD 1003 CD-1003
0 AB 1004
1 AA 1005 AA-1005
Output:
Level Prefix Base Concat OP
0 JH 1000 KB-1001;BC-1002;CD-1003
0 AB 1004 AA-1005
This thread has me totally lost? It appears that rather than creating a dynamic folder name, these responses are parsing data and slinging all over the place. Can someone please walk me through something like this:
1. Period = 2022-08 (or 2022-07, 2022-09, etc.)
2. Line = L1 or L2 or L3, etc.
Current path = c:\documents\Alteryx\
I'm pulling data for August of 2022. If folder "2022-08" doesn't exist, create a folder named "2022-08".
Place files "L1" (or L2, or l3, or whatnot) into folder "2022-08".
I can get the dynamic file name to work by using the "line" field, creating one file for each Line, but since there is no folder called 2022-08, it's blowing up. I'm using a dynamic path with a formula called "Path" - 'c:\documents\alteryx\' + [period] + '\' + [line]
If the folders are pre-created it works fine with finding the correct folder and writing the correct line, it just won't create a folder.
I think you need quotes around both full paths, not only in "if not exist" command. Example: 'if not exist "' + [Directory] + 'Output\" mkdir "' + [Directory] + 'Output\"'