How to add 'del ' as leading sttring of all lines of a file ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vorticity
Posts: 1
Joined: 02 Jun 2020 11:16

How to add 'del ' as leading sttring of all lines of a file ?

#1 Post by vorticity » 02 Jun 2020 12:10

Hi all,

I am regularly updating files to my website www.vorticity.de - meteorological data.
Procedure: files are regularly overwritten by files with identical name, but new data.

Problem: Due to any Proxy or cache, only overwriting files does not guarantee that files with
new data are delivered to any browser call - deleting old files before uploading new files helps!

Solution: Delete files file1.jpg file2.jpg ... before uploading file1.jpg file2.jpg ... using ftp del

My problem: writing file1.jpg file2.jpg ... into a file for the ftp_delete_script is easy...

> but how can I put 'del ' as leading string of each line with a filename ?

Should be easy and I am sure, some of you know better and smarter than me by guessing...!

Thanks for any constructive help!

To repeat in short: I create a file D:\FTP\xftp_upload.cmd to delete existing files as follows

ftp -s:d:\FTP\xftp_upload.txt

The file xftp_upload.txt should look as follows
open ftp.vorticity.de
user
password
del file1.jpg
del file2.jpg
del file3.jpg

The problem is how to write the leading string 'del ' before each line of the file,
the filenames are easy using dir > xftp_upload.txt

Any help more than welcome!

Regards, Bernd.

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: How to add 'del ' as leading sttring of all lines of a file ?

#2 Post by pieh-ejdsch » 03 Jun 2020 09:01

vorticity wrote:
02 Jun 2020 12:10
My problem: writing file1.jpg file2.jpg ... into a file for the ftp_delete_script is easy...
You write this into this - how?
Manually...
Is a list with this files there?

Phil

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to add 'del ' as leading sttring of all lines of a file ?

#3 Post by ShadowThief » 03 Jun 2020 11:49

Do you want to delete all of the files in the directory you're uploading to, or just the ones with the same filename? The FTP command mdel *.jpg will delete all of the JPG files from the target directory on the FT P server.

Otherwise, you can use dir in a for loop, like this:

Code: Select all

for /f "delims=" %%A in ('dir /b') do echo del %%A >>xftp_upload.txt

Post Reply