0

During the course of a batch file, a path like the following is stored in temp.txt:

c:\folder1\folder2\.

The period at the end is just because the path is generated from a for /r %%a in (.) statement. I try to get rid of this using the world famous jrepl.bat search and replace batch file, escaping the backslash with a double-backslash:

type temp.txt|jrepl "\\." "" >temp2.txt

Only problem is that this produces strange results because the search string is interpreted as a regular expression instead of a literal string. So then I tried this as instructed by the jrepl documentation:

type temp.txt|jrepl "\\." "" /l >temp2.txt

...but then for some reason nothing changes. The trailing \. at the end of the URL unfortunately remains intact. I have no idea what I'm doing wrong...

fortissimo
  • 51
  • 8
  • I assume an X-Y problem. I'm interested in your full `for` command because I'm not able to replicate your output with your snippet. – Stephan Jan 08 '23 at 09:29
  • I agree with the above. It is likely that the trailing `\.` can be prevented in the first instance. Also, even if it couldn't be avoided, there are ways of doing this without having to resort to a third party hybrid script with a very large list of possible options. – Compo Jan 08 '23 at 11:53
  • You wouldn't have that output to fix fortismo, if you instead replaced `(.)` with `(*)`. – Compo Jan 08 '23 at 17:37
  • Sorry, the original 'for' command wasn't `/f`, it was `/r`. Here is the command: `for /r %%f in (.) do call :RPWP "%%f"` One of my original solutions was to replace the `(.)` with `(*)`, but it didn't work - can't remember why. I just remember it made things way worse. I am 100% sure that my entire 1000 line batch file is just littered with inefficiencies and duct tape absurdities, but what can I say, I'm just an amateur (not a computer professional) who barely has time to scratch and claw at what I can. – fortissimo Jan 08 '23 at 19:08
  • Also @Compo I am totally with you. I always want the simplest solution I can find that won't die (like a `srch.exe` file I had 20 years ago), and generally searching/replacing text from the command line has proven to be something that's way harder to find solutions to than I thought. Originally I used `repl`, then I figured I had to switch to `jrepl` because I've seen a bunch of people asking questions about `repl` and they're just told `repl` has been abandoned and replaced with `jrepl`. This is the only solution I've found that doesn't rely on putting eggs into an untrustworthy .exe basket. – fortissimo Jan 08 '23 at 19:12
  • There is absolutely no reason why replacing the incorrect `.` with the correct `*` would not work. Please try these three commands in a batch file and take a look at their output, 1. ```@For /R "%LocalAppData%" /D %%G In (.) Do @Echo %%G``` 2. ```@For /R "%LocalAppData%" /D %%G In (.) Do @Echo %%~fG``` 3. ```@For /R "%LocalAppData%" /D %%G In (*) Do @Echo %%G```. Then report back any differences in the results, or any errors which occur. – Compo Jan 08 '23 at 19:56
  • @Compo, I finally got around to replacing all of my `(.)` references with `(*)` and found out the hard way why this is not a good solution. When you use `(*)`, the recursive search omits the current directory, while `(.)` begins with the current directory. In my recursive search, I need the current directory to be included. – fortissimo Jan 15 '23 at 00:46
  • You didn't say that was a requirement – Compo Jan 15 '23 at 01:23
  • Yes, I also said that I tried `*` early on and couldn't remember why it didn't work. I didn't know that excluding the current folder in a recursive search was even in the realm of possibility, without going out of one's way with special code to exclude it. So, I'm not sure how I should have known to include that specification as a requirement. – fortissimo Jan 15 '23 at 07:38

1 Answers1

1

Just answered my own question. Once I added the /l option, I no longer needed to escape the backslash, so what works ends up being:

type temp.txt|jrepl "\." "" /l >temp2.txt

Almost deleted this whole question but figured maybe 2 more people might encounter this issue over the next 750 years, so what the heck.

fortissimo
  • 51
  • 8