Batch file script add file '

Soldato
Joined
19 Oct 2002
Posts
2,518
Location
South London
Hello i've got a batch file script which lists mp4 files within a folder "dir /b *.mp4 > VideoList.txt" which gives me below within a text file

The Time Tunnel - S01E01
The Time Tunnel - S01E02
The Time Tunnel - S01E03

Thing is i need to add file ' to the beginning of each file name like below but i don't have a clue what to add as i'm a bit thick when it comes to this type of stuff

file 'The Time Tunnel - S01E01
file 'The Time Tunnel - S01E02
file 'The Time Tunnel - S01E03
 
Last edited:
Soldato
Joined
24 Sep 2015
Posts
3,673
I'd probably do it in PowerShell rather the a command prompt. This should do what you want:

Code:
Get-ChildItem *.mp4 | ForEach-Object { $_.Name } | ForEach-Object {"'" + $_ } | Out-File VideoList.txt
 
Associate
Joined
2 Jul 2003
Posts
2,436
Powershell:
Code:
(Get-ChildItem -Path "C:\Temp" -Filter *.mp4).Name | % {"file '$_"} | Out-File -FilePath "C:\Temp\VideoList.txt"

Doh, beaten to it!
 
Man of Honour
Joined
13 Oct 2006
Posts
91,147
Code:
@ECHO OFF
ECHO|SET /p="">VideoList.txt
FOR /F "tokens=1" %%F IN ('DIR *.mp4 /B') DO (
ECHO file '%%F' >> VideoList.txt
)

I tend to use that method for more flexibility though the one line version works.
 
Last edited:
Back
Top Bottom