Batch file script add file '

Soldato
Joined
19 Oct 2002
Posts
2,520
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:
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
 
Powershell:
Code:
(Get-ChildItem -Path "C:\Temp" -Filter *.mp4).Name | % {"file '$_"} | Out-File -FilePath "C:\Temp\VideoList.txt"

Doh, beaten to it!
 
Try:

Code:
for %a in (*.mp4) do echo file '%a >> VideoList.txt

Just be aware that if you run it multiple times it will keep appending to the file.

Thanks all for the help PS did try above but it didn't give me a text file so changed to below which worked

(for %%i in (*.mp4) do @Echo file '%%i') > VideoList.txt
 
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