Append Filename of Txt Files on a Line Inside the File Notepad++ - regex

I 'm not a coder/programmer so my knowledge about regex is limited on what I can find on Google and sites like stackoverflow.
I have a series of files, around 10k with different filenames. Now I want to put the specific filename of each file into a line within the txt file, preferably on the first or last line of the file.
So if I have a file with the filename Caste "System in Nepal.txt" I want to see "Caste System in Nepal" on either the first or second line of the txt, without the quotes.
Can anybody help me? Thanks a lot. :)

Have a go with the following:
(.+?)\.\w+
The bit in the brackets you'd then use for your file name. This assumes that there is only one dot in the filename before the extension. Otherwise, if you have filenames like Document.name.txt, you'll need a more complex regex.

I'm not sure you can do this from within Notepad++ as you'll need the list of files to begin with. If you already have this then you can use find and replace to find .txt (if they all have the .txt extension) and replace it with nothing. If you have other extensions then try a regexp like \.[^\.]$ and replace it with nothing. That should match the last fullstop and everything after it.
If you don't have the list of files in your text editor then you can get them from a Bourne compatible shell with something like find . -type f -print > ../file-you-want-the-list-in.txt run in the directory with all the files in.

Related

IF in a Regex expresion? (replace something in file names ONLY if file type is xxx)

Ok, I know some regex but this fooling me...
I usually manage every month hundreds of files submited and have to make some checks and replaces before making them available again in our intranet...
I'm doing it locally on hd on Windows, through a file renamer program which can do pcre but only do one line at a time, so all should be in the same regex.
The problem is that I would like to do replacements only if file type is xxx.
For example, replace all spaces for underscores ONLY if extension is jpg|jpeg|jpe
so
this is a test.jpg => this_is_a_test.jpg
this is a another test.jpe => this_is_a_another_test.jpe
this is a test.docx => this is a test.docx
Jpg is an EXAMPLE, I do diferent replaces for each extension and not for all extensions, so something which replaces spaces in the above example in the .docx will be wrong...
is it posible???
You need to find spaces, and then look ahead to see the extension:
(?=.*\.jp(?:g|e)$)
Note the leading space.
Try it here: https://regex101.com/r/ZgDv7S/1
You said you were on Windows, but do you have WSL (Bash for Linux) or something similar available? If so, here is a quick way to do this from the Linux command line:
rename 's/ /_/g;' *.jpg *.jpe
Explanation: rename runs the given Perl script on the name of the specified files.

Use Dreamweaver regex to add file extension

I have a project where I've exported an html file to be sanitized in preparation for a language translation. The problem is that the internal links do not have the ".html" extension. I've solved the problem of erasing the long file paths, but appending the remaining file is the problem.
The raw file path is:
href="https://oldsite.com/folder1/folder2/folder3/actualpage
I use this regex to find all instances of 'https://oldsite.com" and subfolders, adapting it to how many subfolders I have:
(https://oldsite.com)+/[a-zA-Z0-9]+/[a-zA-Z0-9]\w+/[a-zA-Z0-9]\w+/[a-zA-Z0-9]\w+/[a-zA-Z0-9]\w+
Leaving me with "href="actualpage"
The ideal result should be:
href="actualpage.html"
I've been researching this for hours and can't figure out how to append ".html" to the page.
I'm even open to an application or script that can automate this process.
Thanks in advance.
After some research and some tutorials, I found a regex that did the trick. After shortening the file paths to one level, I used the following:
In Dreamweaver:
Find:
href="(.*)" title=
Replace:
href="$1.html" title=
I performed a massive Find/Replace and was able to fix 1500 files in minutes. Regex is my jam!
I hope this helps other regex noobs like myself.

Target file names using Regex

If I have a list of file names in an XML and want to remove all instances where the file name doesn't have a file extension, how can I do this using regular expressions? I need to do the replace in TextWrangler and have no other option unfortunately.
For example, if I have such a list in an XML as:
<name>AAA_A026C032_150522_R4RO.mov</name>
<name>BBB_A016D032_150809_R4RO.aiff</name>
<name>CCC_A026C038_151010_R4RO</name>
<name>DDGS_A006C132_150409_R4RO.mp3</name>
<name>EFFD_B026C001_150607_R4RO</name>
<name>FGHG_A026C032_141215_R4RO.cine</name>
Have can the files without the file extension be targeted using regular expressions? I would like to replace these (clear them) in the output document.
Thanks in advance,
Matt
'(?!>\w+\.[a-zA-Z0-9]+)>(\w+)'
this pattern gets the name of the files without extensions as its first capturing group. I dont know how to use TextWrangler but I assume that with filename string, you can probably figure it out?

Find file names using find command and regex, functioning improperly

We have a Samba server that is backing up to an S3 bucket. Come to find out that a large number of file names contain inappropriate characters and the AWS CLI won't allow the transfer of those files. Using the "worst offender" I build a quick regex check, tested in rubular against another file name to try and generate a list of files that need to be fixed:
([中文网页我们的团队孙é¹â€“¦]+)
The command I'm running is:
find . -regextype awk -regex ".*/([中文网页我们的团队孙é¹â€“¦]+)"
This brings back a small list of files that contain the above string, in order, not individual characters contained throughout the name. This leads me to believe that either my regextype is incorrect or something is wrong with the formatting of the list of characters. I've tried types emacs and egrep as they seem most similar to regex I've used outside of a Unix environment to no luck.
My test file name is: this-is-my€™s'-test-_ folder-name. which, according to my rubular tests, should be returned but isn't. Any help would be greatly appreciated.
Your regex .*/([中文网页我们的团队孙é¹â€“¦]+) expects one of the special characters after the slash and your test file doesn't start with one of these characters.
You might try something more like .*[中文网页我们的团队孙é¹â€“¦]+.* instead.

Regex in file names

I use free little program Metamorphose for changing file names.
Problem is I need to use regex to change names in order as shown below:
Find: nice-tree-([\s\S]*?)
Replace: nice-tree-$1-abc
As you can see all files that start with nice-tree-ANYTHING should be replaced with -abc at the end of every file name.
I'm everything just not expert for regex usage...
Both of you were right. It works now. Thanks.
Assuming you don't need to replace the full file name with the extension. The following regex would match all the file names that you are looking for.
/nice-tree-.+/