Help for a very specific scenario
Sorry for the vague title, English is my secondary language and don’t know how to describe the issue.
The scenario is this:
<path>./Filename 1/Filename 1.bin</path>
<path>./Filename 2/Filename 2.bin</path>
<path>./Filename 3/Filename 3.bin</path>
And i want to do it like this:
Basically i moved all the bin files in the main folder instead of having one subfolder for every single file. But they are thousands of them and need a way to batch fix the paths in the .cfg file.
@Imgema Do I understand correctly that you want to edit a .cfg file that is in XML format?
If so, the steps are easy. Hit
ctrl+Hwhich pops up a Replace dialog box. On the lower left of the box mark the radio button “Regular Expression”. In the Find field of the box enter:
\./Filename \d+/and enter
./in the Replace field. Place the caret (cursor) at the beginning of your .cfg file and hit Replace All. That should do it.
Yes, its a xml file.
The “filename” example indicates a random name. It could be “Sonic” or “Super Mario” or whatever. There are thousands of different filenames. Each file is in its own folder with the same folder name.
So i got rid of the subfolders and now i need to delete them from the xml as well. But each one has a different name. I don’t know what the “filename” in the solution represents though. Is it literally the word filename?
I’ll try this out when i get back home. Thanks for the reply.
You’re pretty close to becoming a regex non-learner but I’ll give you one more because I wrote the solution before I looked at your posting history.
Search mode: Regular expression
Not sure how to respond. I have learned to use Notepad++ over the years for my projects and use it pretty often but sometimes i’m stuck because something i’m trying to do is more complex and maybe i’m not that smart and things get over my head. That’s why i ask here for solutions.
Anyway, these particular solutions don’t seem to work for me, i’ll try to figure it out.
Thanks for the response.
The “filename” example indicates a random name. It could be “Sonic” or “Super Mario” or whatever.
Then why did you make your example input very regular, which implies to all helpers that there’s some consistent prefix to your data? If that prefix is not consistent, your example input needs to indicate that (by not using consistent dummy data), otherwise you are effectively sabotaging our attempts to give you good answers based on the data you supply.
You’ve been asking nothing but regex questions for the year and a half you’ve been coming here [*]. And I’ve twice  posted the list of links you should read to find out how to format your posts, how to ask a good regex question, and how to start learning regex on your own, and yet here we are 19 months after your first question, with no evidence that you’ve taken any of the information in those posts to heart. I’ll post it a third time, along with another piece of boilerplate that you need to take to heart.
- Please Read Before Posting
- Template for Search/Replace Questions
- Formatting Forum Posts
- Notepad++ Online User Manual: Searching/Regex
- FAQ: Where to find other regular expressions (regex) documentation
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
I personally would use something similar to @Alan-Kilborn but a bit more restrictive in that the sub-folder or sub-directory seems to be the same as the file name:
@Imgema I also made the assumption that the folder named “filename” is also exactly the same letter case as the .bin file within that folder. If your names are “something/Something.bin” for example then either change the
(?-i)at the front of the search expression to be
(?i)to make it a case-insensitive match. Doing this though also means it will match
<Path>along with the expected
<path>in your cfg file. If that’s a problem we can get around that.
You could also do just:
That version ignores that the folder name using
[^/]+?which skips over everything that is not a
([^<]+?)part after that skips over everything that is not a
<and also stores it in a capture group that I use in the replacement part.
@Alan-Kilborn Had I known that the directory and file names of the OP were random, then, off the top of my head, I would have written exactly your regex . I learned writing such stuff during the two years that I follow this forum.
During that time I even learned about Guy’s generic regexes. One can use his template for one-line matches:
(?-s)(?-i:BSR |(?!\A)\G).*?\K(?-i:FR), which in this case becomes
(?-s)(?-i:^<path>|(?!\A)\G).*?\K(?-i:\./.+?/). Put this regex into the Find field and put
./in the Replace field. Hit ctrl+home, hit Replace All, and voilà.
Had I known that the directory and file names of the OP were random
I don’t like to, but sometimes you have to infer some extra stuff into what someone has written as their problem statement.
What I got out of @Imgema 's original problem statement was that they wanted to remove leading directories off of some sort of filepath.
use his template for one-line matches: (?-s)(?-i:BSR |(?!\A)\G).?\K(?-i:FR), which in this case becomes (?-s)(?-i:^<path>|(?!\A)\G).?\K(?-i:./.+?/)
I definitely think that is overkill in this case.
When i said the filenames are random i meant they aren’t necessarily named as “filename”. That was just my example so i picked that as a generic name. The only thing that matters is that the subfolder has the exact same name as the bin file inside.
For instance this:
<path>./Filename 1/Filename 1.bin</path>
Could be this:
<path>./Have A Nice Day/Have A Nice Day.bin</path>
It’s a path that leads to a .bin file and there’s a subfolder before that which i want to delete. But because in the .xml file there are thousands of such files and subfolders that follow the same rule, i needed to do it in bulk. I thought it was obvious from the example in the OP so apologies for any confusion and wasted time.
Anyway, this worked:
FIND - \\(.*?)\\(\1) REPLACE WITH - \\$1 SEARCH MODE - Regular Expression
Though at first it didn’t because all the \ were reversed / in the xml.