notepad

Windows Notepad replace paragraph break with a character


I'm using a batch file to collect file names inside a folder:

dir /a /b /-p /o:gen >names.txt

The result is a txt file with file names but has paragraph breaks:

file1.psd
file2.psd
file3.psd

I need to replace the paragraph breaks with a comma so it should be:

file1.psd,file2.psd,file3.psd

Tried \n and ^p but it doesn't work. It works on Word and Notepad++ but if possible, I prefer it be done in notepad (if there's a way). Is there?


Solution

  • It is not possible using Notepad.exe, because that editor does not support finding end of line.

    But, when you create a batchfile like this:

    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET s=
    FOR /f "tokens=*" %%f IN (names.txt) DO SET s=!s!,%%f
    ECHO %s:~1%
    

    The output should look like:

    file1.psd,file2.psd,file3.psd
    

    The "tokens=*" will take care of filenames containing a space.