How do I insert the "current directory"?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
cwigley
Posts: 14
Joined: Fri Apr 21, 2006 2:48 pm
Location: New York, NY

How do I insert the "current directory"?

Post by cwigley »

Hello,
I was hoping I could ask the geniuses in this forum for some help. You've been quite helpful in the past!

I have a bunch of files that I have to paste a directory path into. The directory varies from file to file, and is the actual location of the file itself...they all have a variation of the following syntax:
  • Directory D:\DISC1\Subtitles\Episode1_dut\
The word "Directory" is the only consistent item. The file path changes based on where the file is actually located.

When I load up all 100+ files into text pad, and run a global search & replace, is there a way I can insert a string similar to this?
  • Directory {current file location}
I'm guessing it would involve using the POSIX regular expression syntax?

Thank you!

- Collin
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Regular expressions are used to specify the text to search for, not the text to use as a replacement. And TextPad provides no means to insert the directory of the current document, or any other part of its filename, using its replacement expressions.

But you can create a macro to do it:

Edit | Insert | File Name
Search | Replace:
Find what: \\.*
Replace with: [nothing]

[X] Regular expression
<Shift>+Find next (that is, search backwards)
Replace
<Esc>

If you want to keep the trailing backslash, use
Search | Replace:
Find what: \\.*
Replace with: \

[X] Regular expression
and add a
<Right>
at the end of the macro.

The regular expression above works with either Posix or default syntax.
gan

Post by gan »

I cannot see how this could be solved using textpad. There are other text editors available that could easily do this and also insert the path automatically using macro or scripts. Unfortunately the macro support in textpad isn't very advanced and lack the ability to edit scripts.
cwigley
Posts: 14
Joined: Fri Apr 21, 2006 2:48 pm
Location: New York, NY

Post by cwigley »

Hey!
That actually seems to work really well...

Now if I could link a keystroke to the macro, I would rock thru these in no time! Haha...

Here are my macro steps:
1) Search for text in previous line
2) Replace with "text in previous line\n Directory XX\n"
This basically inserts a new line where I need it, inserts the common word "Directory" that I need in every file, inserts text I can search for and replace with the filename, along with a carriage return.
4) FIND "XX"
Now XX is highlighted, which places the curser in the right spot. I chose XX since it doesn't appear anywhere else in the file.
3) EDIT | INSERT | FILENAME
Since XX is now highlighted, inserting the filename will replace XX with what I need.
4) CTRL+SHIFT+Left Arrow (x3)
since the curser is now at the end of the filename, and i want to remove the actual name of the file, and keep the directory, I shift selected backwards three times. This should always result in removing the filename as long as there are no spaces.
5) SAVE


Maybe there is an easier way to accomplish this, but as I said, it seems to work great!

Thank you for your help Ben,
Collin
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Need a hot key for your macro? No Problem, TextPad does that.

Configure / Preferences / Keyboard /
Categories = Macros
Select Macro and highlight it.
Go to Press New Shortcut Key and press the Shortcut Key combo that you want.
Apply and OK your way back out Configurations.
Hope this was helpful.............good luck,
Bob
cwigley
Posts: 14
Joined: Fri Apr 21, 2006 2:48 pm
Location: New York, NY

Post by cwigley »

Ah HA!

Thank you!
cwigley
Posts: 14
Joined: Fri Apr 21, 2006 2:48 pm
Location: New York, NY

Post by cwigley »

Is it possible to apply a macro to a group of files? Or can you only run a macro on the current open document?

I have all 100+ files loaded into Textpad, and I couldn't figure out how to batch run a Macro. Granted...it was pretty damn quick just clicking down the list and selecting the macro from the File Menu...but i am always looking to cut corners...haha


thank you

Collin
cwigley
Posts: 14
Joined: Fri Apr 21, 2006 2:48 pm
Location: New York, NY

Post by cwigley »

I don't want to waste anyone's time... I did some searching and found this thread.

I'll take it from here...

thanks guys

Collin
Post Reply