Remove folders from txt file in windows cmd

I have file with thousand lines like this.

x:/folder/folder/PN.xxx 
y:/folder/PN.xxx 
...

I need to make script for change this (for using in excel):

x;file.xxx
y;file.yyy

Best result for me is something this:

x;PN;x:/folder/folder/
y;PN;y:/folder/

I try to use easiest way in cmd:

D:\>powershell -Command "(gc serverPN.txt) -replace 'xxx', ';' | Out-File myFile.txt"

But I dont know, what is needet to write in XXX, when i want remove everything between /*/. Something like this can be close:"\\[\D]*\\'".

Thanks for help.


ANSWERS:


Supposing the lines are stored in text_file.txt, for a solution you need a for /F loop and the ~ modifiers for loop variable expansion (see also for /? for details):

for /F "usebackq delims=" %%L in ("text_file.txt") do (
    echo(%%~dL;%%~nxL;%%~dpL
)

This reaults in the following output with respect to the sample data in your question:

x:;PN.xxx;x:/folder/folder/
y:;PN.xxx;y:/folder/

If you want the pure file name without extension in the output, replace %%~nxL by %%~nL.


In PowerShell try:

gc "serverPN.txt" | % { 
    get-item $_ | %{ 
        "$($_.PSDrive);$($_.Name);$($_.Directory)" | Out-File "myFile.txt" -Append 
    } 
}

This should be your requested regular expression: :.*/ and you can replace it with a ;:

powershell -Command "(gc serverPN.txt) -replace ':.*/', ';' | Out-File myFile.txt"

$test = 'C:/test1/test2/test3/test4/testfile.xls'

$newfile =$test.Substring(0,2) + ';' + $test.Substring($test.LastIndexOf('/')+1,($test.Length-$test.LastIndexOf('/')-1))

Output :

C:;testfile.xls

While it is not the beloved PowerShell, cmd could also produce the "best result".

C:>TYPE fi2.bat
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /F "usebackq tokens=*" %%f IN (`TYPE fi2.txt`) DO (
    SET DRIVE=%%~df
    SET DRIVE=!DRIVE:~0,1!

    SET FILENAME=%%~nf

    SET DIRNAME=%%~pf
    SET DIRNAME=!DIRNAME:\=/!

    ECHO !DRIVE!;!FILENAME!;%%~df!DIRNAME!
)

EXIT /B 0

C:>CALL fi2.bat
x;PN;x:/folder/folder/
y;PN;y:/folder/


 MORE:


 ? replacing line in txt file AFTER specific line
 ? How to concatenate 2 .csv files in 1 .csv file with multiple sheets using Batch commands
 ? How to remove strings from a text file using batch script?
 ? How to remove strings from a text file using batch script?
 ? How to remove strings from a text file using batch script?
 ? How do I check that a parameter is defined when calling a batch file?
 ? Batch To Remove Character From A String
 ? How to edit multiple text lines in a .ini file using batch script
 ? batch script to copy a set of lines from the text file and paste the values in another text file
 ? Batch Script - How to write to single line of a text file