Writing to a file that contains a Pipe - Forum

Forum Navigation
You need to log in to create posts and topics.

Writing to a file that contains a Pipe

I am pulling my hair out trying to figure out how to to filewrite a bat file that contains a pipe.

@echo off
(
    for /f "tokens=5* delims= " %%i in ('dir "D:\downloads" /AL ^| find "<SYMLINK>"') do @echo D:\downloads\%%i %%j
) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas

No matter how I set the multi line settings (I tried all three) when setting my variable, it always either truncates at the pipe, or it line breaks at the pipe and the pipe disappears.   I replaced the pipe with [#124] and that didn't help.  And I'm outta ideas.

Anyone know how this might be possible?   Currently I have

SetVar "[ForBat]" "@echo off|(|    for /f [#34]tokens=5* delims= [#34] %%i in ('dir [#34]D:\downloads[#34] /AL ^| find [#34]<SYMLINK>[#34]') do @echo D:\downloads\%%i %%j|) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas"
FileWrite "[PubDir]lst.bat" "All" "[ForBat]"

Thanks in advance ;-0

SetVar "[ForBat]" "@echo off[#124]([#124]    for /f [#34]tokens=5* delims= [#34] %%i in ('dir [#34]D:\downloads[#34] /AL ^[#124] find [#34]<SYMLINK>[#34]') do @echo D:\downloads\%%i %%j[#124]) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas"
FileWrite "[PubDir]lst.bat" "All" "![ForBat]"

 

Thanks @mishem,

But the output is still:

@echo off
(
    for /f "tokens=5* delims= " %%i in ('dir "D:\downloads" /AL ^
 find "<SYMLINK>"') do @echo D:\downloads\%%i %%j
) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas

Which breaks right aft4er the /AL^

Thanks for giving it shot.  Most appreciated.

@rcohen,  I don't know if this is it or not but maybe this works?

SetVar "[ForBat]" "@echo off[#124]([#124]    for /f [#34]tokens=5* delims= [#34] %%i in ('dir [#34]D:\downloads[#34] /AL [#94][#124] find [#34]<SYMLINK>[#34]') do @echo D:\downloads\%%i %%j[#124]) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas"
FileWrite "[PubDir]lst.bat" "All" "![ForBat]"

which outputted this:

@echo off|(|    for /f "tokens=5* delims= " %%i in ('dir "D:\downloads" /AL ^| find "<SYMLINK>"') do @echo D:\downloads\%%i %%j|) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas

Brad

@rcohen

Sorry, I didn't check... I just glanced at it now, everything seems to be in place...
Where it breaks, that's where it needs to be fixed. You can even replace the entire text with special characters. ;)
Maybe I'm looking at the wrong thing? Very bad translation, hard to understand the problem...I'm just doing telepathy. :)

 

SetVar "[ForBat]" "@echo off[#124]([#124]    for /f [#34]tokens=5* delims= [#34] %%i in ('dir [#34]D:\downloads[#34] /AL [#94][#124] find [#34]<SYMLINK>[#34]') do @echo D:\downloads\%%i %%j[#124]) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas"
FileWrite "[PubDir]lst.bat" "All" "![ForBat]"

 

@darbdenral

I didn't look at it right away, you have exactly the same answer. One head is good, but one and a half is better. This is my other half. :)

Darbdenral has reacted to this post.
Darbdenral
Quote from mishem on February 24, 2025, 12:13 am

@darbdenral

I didn't look at it right away, you have exactly the same answer. One head is good, but one and a half is better. This is my other half. :)

@mishem  I couldn't have done it without my other half either ;)

Yes, there is one small character I changed, can you find it ??

I replaced the  ^ char with [#94]

 

 

Wow, thanks guys for the help.

I still had to modify a few things, as some of those pipes I discovered were new line indicators, but they didn't work even as [#124].   And so by comparing a working script with the output I was able to discover that three of the [#124]'s had to be changed to [#13][#10]

And so NOW, it works as:

SetVar "[ForBat]" "@echo off[#13][#10]([#13][#10]    for /f [#34]tokens=5* delims= [#34] %%i in ('dir [#34]D:\downloads[#34] /AL [#94][#124] find [#34]<SYMLINK>[#34]') do @echo D:\downloads\%%i %%j[#13][#10]) >> D:\NeoBook_Pubs\CloudStudioStation\cleanup.sas"

Thanks a ton guys.  If it weren't for your help I would have NEVER found this.

Many thanks.

And if I can ask you guys (or anyone) if the following reg grab, gets the correct default download folder on your system, I'd sure appreciate that.  Wanna be sure this works for everyone and not just me ;-)

RegistryRead "HKEY_CURRENT_USER" "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\{374DE290-123F-4565-9164-39C4925E467B}" "[SystemDownloadFolder]"

Thank you.

@rcohen

 

 

Uploaded files:
  • You need to login to have access to uploads.
rcohen has reacted to this post.
rcohen

Спасибо за подтверждение.  ;-)