I am trying to make a script that will copy the contents of one project to another (ie folders and modules) in DXL. To do it, I have seen that there is the create function,
create(string name, string description)
which creates a folder... But from what I see, it creates it in the current directory where I run the script.
Is there any way that running the script in the M module, from the C folder of the P project, generates a folder with the same name C but inside the new NP project?
Thanks:)
from the DXL manual: The name argument can be an absolute or relative name, and may include the path.. So, you might have a loop like
Project P = project ('/P')
Item i
for i in P do {
if (type i == 'Folder') {
string nName = name i
create ("/NP/" sName, "")
}
// recursively copy the content of the folder
}
Also, depending on your needs, you might want to have a look at clipCopy and clipPaste, which duplicates an entire hierarchy.
Related
I am trying to create a lambda function that will get triggered once a folder is uploaded to a S3 Bucket. But the lambda will perform an operation that will save files back on the same folder, how can I do so without having a self calling function?
I want to upload the following folder structure to the bucket:
Project_0001/input/inputs.csv
The outputs will create and be saved on:
Project_0001/output/outputs.csv
But, my project number will change, so I can't simply assign a static prefix. Is there a way of dynamically change the prefix, something like:
Project_*/input/
From Shubham's comment I drafted my solution using the prefix and sufix.
For my case, I stated the prefix being 'Project_' and for the suffix I choose one specific file for the trigger, so my suffix is '/input/myFile.csv'.
So every time I upload the structure Project_/input/allmyfiles_with_myFile.csv it triggers the function and then I save my output in the same project folder, under the output folder, thus not triggering the function again.
I get project name with the following code
key = event['Records'][0]['s3']['object']['key']
project_id = key.split("/")[0]
In my project I'm frequently passing one AccountID in different packages and classes and that accountid is hardcoded wherever it used.
This AccountID may change for some resons in the future. And in order not to go over all files in my my project and replace it, I want to write it in one place.
I heard that there are some properties in IntelliJ where I can do that. I don't know how to google my problem, so if you have any sources, please share.
I think you should use the Properties.class for that purpose.
just write a txt file anywere (I recomend your Resources folder) and name it to "myProperties.properties" for instance
The text in your propertiefile would look like the following:
AccountID = "whateverIDyouWant"
to get the data of your propertiefile call:
Properties props = new Properties();
FileInputStream in = new FileInputStream("G:\\your\\path\\myProperties.properties");
props.load(in);
in.close();
String AccountID = props.getProperty("AccountID");
if your AccountID is an int just parse your string using Integer.parseInt(yourString);
if you want to set your properties through hard code, that can also be done:
props.setProperty("AccountID", "whateverIDyouWant");
Edit:
to create a resources folder, create a folder in your classpath. Afterwards go to the "Project view" in IntelliJ. Rightclick the new folder and select "Mark directory as" -> "Sources Root". Thats how its done.
I have a directory called auction containing a list of xml files.
How can I create a script to iterate through each file and perform operations. I am trying to use collection(), but it is not working.
for $relpath in collection("auction")
for $b in $relpath/people/person[#id = "person0"] return $b/name/text()
Please help.
More info will be provided if required
The answer was found here:
https://groups.google.com/forum/#!topic/zorba-users/8W2xOQ2j0Vw
Modified it to suit my purposes. An example is as follows:
import module namespace file="http://expath.org/ns/file";
for $relpath in file:list("auction", fn:true(), "*.xml")
let $abspath := fn:concat("auction/", $relpath)
for $b in doc($abspath)/people/person[#id = "person0"] return $b/name/text()
Firstly, the module needs to imported to be used which contains the list function, which shows all the contents.
Then the iterations can go through each file and open it as a document. However, the name of the folder needs to concatenated with the filename
In my app, I generate some xml file for instance : "/xml/product/123.xml" where 123 is the product's id and 123.xml contains informations about this product. I also have "/xml/customer/123.xml" where 123.xml contains informations about the client ... 123
How can I manage these file paths :
I create the file path directly in the serialization method ?
I create 2 static classes : CustomerSerializationPathManager and ProductSerializationPathManager with 1 method : getPath(int customerID) and getPath(int productID)
I create one static class : SerializationPathManager with 2 methods : getCustomerPath(int customerID) and getProductPath(int productID)
Something else
I'd prefer solution 3 because if I think there's only one reason to change this class : I change the root directory.
So I'd like to have your thoughts about it... thx
If you need to save the files in specific folders and the location of these files can change, then you should move this information in a configuration file and later use if from there.
You then create a class similar to a factory, with getPathForProductExports, getPathForCustomerExports etc which reads the configuration file to return the desired path.
The configuration file can be a simple .properties file:
customer_path=/xml/customer/
product_path=/xml/product/
When generating the XML (be it customer, product or whatever) you prepend the appropriate path (getPathForCustomerExports, getPathForProductExports) to the file name.
If you later change the location you just edit the config file.
I have a really quick question. My program actually downloads a zip file then extracts it onto their desktop. But I need an uninstall feature for it, which is basically deleting multiple folders and containing files. How can I do this in vb.net?
If all of your folders are contained in a single folder, it should be pretty straight forward.
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YOURPATH"
System.IO.Directory.Delete(path, True)
That will delete your root directory, and all the directories and files below it. You could just call this several times over if your files and directories are not all in a single root directory like "YOURPATH" in the example. This will spare you from having to remove each file individually.
The .NET IO unit has a two commands that should let you do the trick:
System.IO.Directory.GetDirectories("C:\\Program Files\\Your Directory\\*.*");
System.IO.Directory.GetFiles("C:\\Program Files\\Your Directory\\*.*");
I would write a method that takes the name of a directory and uses the "GetFiles" routine to get all of the files and to delete them using System.IO.File.Delete(path) in a foreach loop. Then, run a foreach loop on the result of the GetDirectories() command calling the function recursively.
Update: Steve Danner points out that the System.IO.Directory namespace has a Delete method so you don't need to go through the loops I talk about here. His answer is the right one and should be voted up. Mine, at this point, is more of a curiosity (although thank you to the person who gave me an upvote ;0).
Your are looking for DirectoryInfo, use it like this:
Dim di As New IO.DirectoryInfo(path)
di.Delete(True)
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\YOURPATH"
System.IO.Directory.Delete(path, True)