Inserting Filename

General discussions about Advanced Find and Replace
Post Reply
Millzee
Posts: 4
Joined: Wed May 25, 2005 6:28 am

Inserting Filename

Post by Millzee » Wed May 25, 2005 6:40 am

Hi

I have just come across your app and I'm hoping its going to be able to help save my skin!

I have approx 40K .xml files all looking similiar to :-

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<fields>
<field id="Client_Name">XXXXXXXXXX</field>
<field id="Date_In_System">20041209</field>
<field id="Status"></field>
<field id="Document_Class"></field>
<field id="Document_Overview"></field>
<field id="Administrator"></field>
</fields>

What I want to do is insert into each file the filename like :-

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<fields>
<field id="Filename">Filename1</field>
<field id="Client_Name">XXXXXXXXXX</field>
<field id="Date_In_System">20041209</field>
<field id="Status"></field>
<field id="Document_Class"></field>
<field id="Document_Overview"></field>
<field id="Administrator"></field>
</fields>

Is this possible with your app?

sorry if this is a basic question but I have a rather short timeframe to try and resolve this :(

many thanks

Abacre
Site Admin
Posts: 1213
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre » Wed May 25, 2005 8:54 am

Hi,

Your skin will be quickly saved with AFR! :)

Read the page:
http://www.abacre.com/afr/manual/optsba ... ilerenamer

So:

Start the program. In main menu - Action - Options - Batch replace
check ON: "Include File Name into Search Scope".
set correct modifiers:
Modifier S: ON
Modifier G: ON
Press OK.

In Batch Replace tab of the main window:
check ON: "Use regular expressions"
put Search for:
.*\\(.+\.xml)\r\n(.*)<fields>

Replace with:
\r\n$2<fields>\r\n<field id="Filename">$1</field>

That's all. I verified it perfectly works. So if you have the file
name:
C:\Program Files\Advanced Find and Replace\test it.xml

it will produce the resulting file:

Code: Select all

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<fields>
<field id="Filename">test it.xml</field>
<field id="Client_Name">XXXXXXXXXX</field>
<field id="Date_In_System">20041209</field>
<field id="Status"></field>
<field id="Document_Class"></field>
<field id="Document_Overview"></field>
<field id="Administrator"></field>
</fields>


If you need to include the complete file name (with full path) use the
Search for:
(.+\.xml)\r\n(.*)<fields>
Replace with (is the same as above):
\r\n$2<fields>\r\n<field id="Filename">$1</field>

That's it. In this case the resulting file will be:

Code: Select all

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<fields>
<field id="Filename">C:\Program Files\Advanced Find and Replace\test it.xml</field>
<field id="Client_Name">XXXXXXXXXX</field>
<field id="Date_In_System">20041209</field>
<field id="Status"></field>
<field id="Document_Class"></field>
<field id="Document_Overview"></field>
<field id="Administrator"></field>
</fields>


Does it work on your computer?
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Millzee
Posts: 4
Joined: Wed May 25, 2005 6:28 am

Post by Millzee » Wed May 25, 2005 5:51 pm

Wow what a great and quick response.

This is almost exactly what I need, can it be tailored to just put the filename without path or extension so it could like like :-

<field id="Filename">test it</field>

thanks in advance.

Abacre
Site Admin
Posts: 1213
Joined: Mon Jan 31, 2005 5:32 pm

Post by Abacre » Wed May 25, 2005 6:18 pm

Well, then it will be about the same as described in:
http://www.abacre.com/afr/manual/optsba ... ilerenamer
So use search for:
.*\\(.+)\.xml\r\n(.*)<fields>

That's all!
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Millzee
Posts: 4
Joined: Wed May 25, 2005 6:28 am

Ok I have a really strange one now.

Post by Millzee » Wed Jul 06, 2005 7:12 am

Hi

I have used the above and it work fantastically.

However, i have since rebuilt my PC and re-installed the app but now I cannot get it to search any .xml file at all, for either finding or batch replacing.

I am using 2.3 registered.

I'm guessing I have selected a setting somewhere?

Even more wierd, I cant search or replace on files it has previously worked on?

any ideas?

ps. I have emailed you the source and default.cfg file.

Millzee
Posts: 4
Joined: Wed May 25, 2005 6:28 am

Sorted it

Post by Millzee » Thu Jul 07, 2005 6:05 pm

Ok its now working, I just selected "search in subfolders" off then back on and that seemed to do the trick.

cheers and thanks for an amazing app.

Post Reply