Copy file or folder name to clipboard, ignore extension etc

OK... try this one. Let me know...

Copy N bp.dcf (311 Bytes)

Clipboard COPYNAMES REGEX "(.+)\[|\(.+\]|\)" "\1"

Thank you again Dear pctechtv. here is you feedback.

Feedback 1 for Folder Name:
original path is:
D:\Project Secure\Backup v.1 [03-11-2018]\Folder name A [test]
what the button does:
D:\Project Secure\Backup v.1 [03-11-2018]\Folder name A
What I want is: Folder name A

Feedback 2 for Files Name:
original path is:
D:\Project Secure\Backup v.1 [03-11-2018]\Folder name A [test]\File name A [test] - demo.txt
what the button does:
D:\Project Secure\Backup v.1 [03-11-2018]\Folder name A [test]\File name A
What I want is: File name A

If you don't want the paths, you can remove them easily.

Clipboard COPYNAMES copies the full paths to the clipboard.

Clipboard COPYNAMES=nopaths copies just the names to the clipboard.

The REGEX ... stuff in the two commands above will work with both, so you can put that on the end of the command.

e.g. If you think the last regex in the thread was the right one, then this will do the same thing but without the paths:

Clipboard COPYNAMES=nopaths REGEX "(.+)\[|\(.+\]|\)" "\1"

While regex takes a little time to learn & understand, things like the nopaths parameter are all in the manual and easy to learn/use. :slight_smile:

Thanks Leo for helping...
I use this code: Clipboard COPYNAMES=nopaths REGEX "(.+)\[|\(.+\]|\)" "\1"

but the result is not as expected.
What the button dose: "file name A (test).txt"
What I want as result is: "file name A"

Try this:

Clipboard COPYNAMES=nopaths REGEXP "(.+)\(|\[.+\)|\]" "\1"

Dear Jon I try your code, But your code is not work also. its paste the whole code line only.
what the button does: Clipboard COPYNAMES=nopaths REGEXP "(.+)\(|\[.+\)|\]" "\1"
What I want as result is: "file name A"

That's what I get when I try it here.

My Problem steel not solved, Dear Jon, Leo, Community, please help me!

So if you have:

File name A [test] - demo.txt

You want:

File name A

Is that correct? That contradicts what the first post said:

I'm not sure if you want to remove what's inside [...] and (...) or if you want to remove everything after the first [ or ( including things outside of the brackets.

I am sorry Leo I can't make you understand clearly. Ok fine Let me tell you what I want.

  1. Copy file name only (no path) without it's Extension.
  2. Copy Folder name only (no path)
  3. remove what's inside [...] and (...)
    are you clear now Dear Leo?

Are 1 & 2 strict requirements, as in if a folder is named Test.txt it'd be a problem to remove the .txt from it?

It would probably require a script to apply different search & replace logic to files vs folders. But if you aren't expecting/concerned about folders with dots in their names then it's easier and shouldn't need a script.

Thanks for Replay dear Leo. "Are 1 & 2 strict requirements" Yes it is. But their is nothing to worry in folder name about 'dots'. Dots is only problem in the file name only for their Extension. So it should easier as you tell.

In that case:

Fixed regex:

(.+)(\(|\[).+(\)|\]) ?(.*) to \1\4

Command:

Clipboard COPYNAMES=nopaths REGEXP "(.+)(\(|\[).+(\)|\]) ?(.*)" \1\4

Or this, which does the same thing but removes (...) and [...] using two separate regex instead of a combined one, which might be easier to read. Or not.

Regex:

(.+)\(.+\) ?(.*) to \1\2
(.+)\[.+\] ?(.*) to \1\2

Command:

Clipboard COPYNAMES=nopaths REGEXP "(.+)\(.+\) ?(.*)" \1\2 "(.+)\[.+\] ?(.*)" \1\2

Thanks Dear Leo for helping. But My Problem is not completely solved. Here is your feed back for 2 Code

Clipboard COPYNAMES=nopaths REGEXP "(.+)(\(|\[).+(\)|\]) ?(.*)" \1\4
Clipboard COPYNAMES=nopaths REGEXP "(.+)\(.+\) ?(.*)" \1\2 "(.+)\[.+\] ?(.*)" \1\2

Original Folder name: ABCD [test]
After Using This Code: ABCE
Feed Back: here is a extra Space also paste After the folder name "ABCE (space)" which I don't want. If possible plz remove the extra Space & fix That code.

Original File Name : ABCE (test).txt
After Using This Code: ABCE .txt
Feed Back: Big problem is here is the File Extension. another problem is the extra space After the File name Like the Folder name. Please Remove The File extension & the extra Space with fix the code.

Try this:

Clipboard COPYNAMES=nopaths REGEXP "(.*[^ ]) ?(\(|\[).+(\)|\])(.*)" \1\4

Thaks Leo for replay.
Extra Space is fixed But The file Extension is not Fixed.

Original File Name : ABCE (test).txt
After Using This Code: ABCE.txt
Feed Back: Big problem is here is the File Extension. Please Remove The File extension for fix the code.

Try this:

Clipboard COPYNAMES=nopaths REGEXP "(.*[^ ]) ?(\(|\[).+(\)|\])(.*)" \1\4 (.*)\.[^\.]+$ \1

I recommend learning regular expressions so you can do this yourself, as it's be much faster than waiting for us to get exactly what you want.

Thanks Leo, Problem Solved
Where can I Learn regular expressions?

We have an introduction to them here:

Google also has pages of tutorials if you just search for "regular expressions". I'm not sure which to recommend, but I'm sure at least some of them are good.

Thanks Leo