Pergunta

Ok so I have a script:

gc .\oauthrn.cms |
    % {
        $a=@();
        $b="";
        $a += $_.split('|'); 
        for ($i=0;$i -lt 168; $i++) 
        {
            $b += $a[$i] + '|'
        } 
        $b
    } |
    % {
        $_.TrimEnd("|")
    } |
    out-file "H:\Documentation\Scripts\Pipe Delimiter Project\ShineyNewFile.txt" -encoding ASCII

gc .\oauthrn1.cms |
    % {
        $a=@();
        $b="";
        $a += $_.split('|'); 
        for ($i=0;$i -lt 168; $i++) 
        {
            $b += $a[$i] + '|'
        } 
        $b
    } |
    % {
        $_.TrimEnd("|")
    } |
    out-file "H:\Documentation\Scripts\Pipe Delimiter Project\ShineyNewFile1.txt" -encoding ASCII

Problem

So basically I would like to rename the file the original name, but when I name the ShineyNewFile, oauthrn, it doesn't output anything in the file.

I imagine it's because it's still looking at that file to output during the out-file statement...

Does anyone have any insight on this? Is my assumption correct? Is there some way to handle this keeping the syntax I am currently using? I am new to powershell, but it is a great tool.

Foi útil?

Solução

So, I'm not sure why you have most of that in the script since the TrimEnd gets rid of all the extra pipe characters from the last question you asked that I saw, but anyway, does this do what you want?

gc .\oauthrn.cms |
    % {$_.TrimEnd("|")} |
    out-file "H:\Documentation\Scripts\Pipe Delimiter Project\ShineyNewFile.txt" -encoding ascii
Rename-Item "H:\Documentation\Scripts\Pipe Delimiter Project\ShineyNewFile.txt" "oauthrn.cms"

gc .\oauthrn1.cms |
    % {$_.TrimEnd("|")} |
    out-file "H:\Documentation\Scripts\Pipe Delimiter Project\ShineyNewFile1.txt" -encoding ascii
Rename-Item "H:\Documentation\Scripts\Pipe Delimiter Project\ShineyNewFile1.txt" "oauthrn1.cms"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top