You are not logged in.
Announcement
Unanswered posts
|
Pages: 1

Hi,
I've got several folders. In each folder, there is a XML file.
Now I want to count the folders (let's say I've got 17 at this run).
After that I want to iterate through the folders, open the XML file search for the line:
<Attachment id="">
and put in the number of the current folder.
<Attachment id="01"> for the first folder, <Attachment id="02"> for the second, and so on.
The order doesn't matter.
How can I do this?
I guess I need fileList and there is a loop component. Can I use them together for this purpose?
Thank you in advance.
Bye, CHris
Offline
Hello Chris
You need to use one tFileList to iterate folders and another tFileList to iterate file, then write some Java code to search the string and insert a specify value into it.
Here I show you an example, I search the following line and put the current folder name in it. eg:
Assuming there is a file: out1.xml in folder: D:\file\test2\folder1
I search the specify line and put the folder name in it,
<Attachment id="folder1">
First, go to Resipotory-->code-->Routines and create a routine call: forum6953
package routines;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class forum6953 {
public static void serarchAndEdit(String folderPath, String filePath) {
FileInputStream fis = null;
FileOutputStream fos = null;
String folderName = folderPath
.substring((folderPath.lastIndexOf("\\") + 1));
System.out.println(folderName);
try {
fis = new FileInputStream(filePath);
byte[] b = new byte[fis.available()];
fis.read(b);
String s = new String(b);
s = s.replaceFirst("<Attachment id=\"\">", "<Attachment id=\""
+ folderName + "\">");
b = s.getBytes();
fos = new FileOutputStream(filePath);
fos.write(b);
} catch (Exception e) {
e.printStackTrace();
}
}
}Please see my screenshots
Best regards
shong
Offline

Hi,
thank you very much.
But unfortunately my folders have an ID .. like 1681631 or 98357 so I can't use these names.
That's why I came up with the tLoop component.
Can I access the current variable from tLoop (depending on whether there is a folder or not) inside your routine?
Like:
i = 1;
while ( folder.exists () )
{
id = i;
folder.next ();
i++;
}Bye, Chris
Offline
Hello
But unfortunately my folders have an ID .. like 1681631 or 98357 so I can't use these names
What's your real folder name? Why do you say ' I can't use these names'? What are your expected result?
Can you describe your request more precise? Some screenshot will be better
Best regards
shong
Offline

Hi,
ok, here are the screenshots
topfolder:
There is a XML named: 56-13638866.xml
subfolder:
I've got 0...n subfolders. Within theses subfolders, there is a XML and a JPG. Now I need to tell the XML the number of this subfolder.
<Attachment id="attachement_"> <File>56-13638867.jpg</File>
Depending on the number of the folder (folder 1, folder 2, folder 3 - disregarding its name: 56-13638867) I want to put this number into the code to change it into:
<Attachment id="attachement_001"> <File>56-13638867.jpg</File>
and the next one into:
<Attachment id="attachement_003"> <File>56-13638867.jpg</File>
etc.
Hope I expressed it well?
Best regards,
Chris
Offline
Hello
Hope I expressed it well?
Yes, I understand well, I make a little change on my routine to generate a sequence number for each xml file.
package routines;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class forum6953 {
public static void serarchAndEdit(String folderPath, String filePath) {
FileInputStream fis = null;
FileOutputStream fos = null;
int id = Numeric.sequence("s1", 1, 1);
try {
fis = new FileInputStream(filePath);
byte[] b = new byte[fis.available()];
fis.read(b);
String s = new String(b);
s = s.replaceFirst("<Attachment id=\"\">", "<Attachment id=\"" + id
+ "\">");
b = s.getBytes();
fos = new FileOutputStream(filePath);
fos.write(b);
} catch (Exception e) {
e.printStackTrace();
}
}
}If you know Java a little, you can modify it a little to fit your request more close.
Best regards
shong
Offline
Pages: 1