Open file and save in different format

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tim120harvey
Posts: 4
Joined: 19 Sep 2012 08:02

Open file and save in different format

#1 Post by tim120harvey » 19 Sep 2012 08:09

Hi all,

I need to open up a file and then save it in a different format.i.e.
Open C:\Book1.err
Save as C:\Book1.txt
Close

I will have many files, with varaiable names, but always ending '.err'

Once opened and saved, I would also like to move the original file to a new location (to prevent duplication of the save as).
C:\Loaded\Book1.err

Is it possible to do this via a .bat file? If so, with what code?
Many thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Open file and save in different format

#2 Post by foxidrive » 19 Sep 2012 08:17

I'd like to clarify the task:

1) Are these .err files in a single directory?

2) Do you want each .err file to be duplicated, and be given a .txt extension?

3) if the .err files are in subdirectories, what do you need to do if two .err files have the same name?

tim120harvey
Posts: 4
Joined: 19 Sep 2012 08:02

Re: Open file and save in different format

#3 Post by tim120harvey » 19 Sep 2012 08:24

Hi,
Thanks for the quick reply.
1) Yes
2) Yes - the .txt file to remain in the original directory, the old .err file to be moved to the new subdirectory
3) There will never be duplicate names, the files are sequentially named, to prevent duplication

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Open file and save in different format

#4 Post by foxidrive » 19 Sep 2012 08:42

This is untested so test it in a dummy folder with dummy files first.

Code: Select all

@echo off
for %%a in (*.err) do (
copy /b "%%a" "c:\loaded" >nul
ren "%%a" "%%~na.txt"
)

tim120harvey
Posts: 4
Joined: 19 Sep 2012 08:02

Re: Open file and save in different format

#5 Post by tim120harvey » 19 Sep 2012 08:53

Hi,
Nearly there!

This has changed the files from .err to .txt (great!!), but I no longer have the original .err files
(it has not copied, it has just renamed)

I want to save a copy of the originals to the C:\Loaded file and leave the new .txt files in C:\

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Open file and save in different format

#6 Post by foxidrive » 19 Sep 2012 08:58

Does c:\loaded actually exist yet? Create the folder and it will copy them.

tim120harvey
Posts: 4
Joined: 19 Sep 2012 08:02

Re: Open file and save in different format

#7 Post by tim120harvey » 19 Sep 2012 09:04

You are a hero!!

Thanks for your help!!

Post Reply