Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

Can I save (or save as) an open text file using a batch?

I have opened a .txt file using a batch.  Now, I would like to save as "new file name.txt".
Example:
I open the text file using %SystemRoot%\explorer.exe "my path\MyAccount.txt"

I would like to save as "AnyFile.txt"
0
NNiicckk
Asked:
NNiicckk
  • 4
  • 3
3 Solutions
 
ZoppoCommented:
Hi NNiicckk,

why don't you simply copy the file?

ZOPPO
0
 
MontoyaProcess Improvement MgrCommented:
Use copy command to copy the file and change the destination, therefore name

here's the reference:
Copies one or more files to another location.

COPY [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
     [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

  source       Specifies the file or files to be copied.
  /A           Indicates an ASCII text file.
  /B           Indicates a binary file.
  destination  Specifies the directory and/or filename for the new file(s).
  /V           Verifies that new files are written correctly.
  /N           Uses short filename, if available, when copying a file with a
               non-8dot3 name.
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).
0
 
NNiicckkAuthor Commented:
The file, for some reason, shows a couple of blank data fields as [] [] [] [] when I use through Monarch.  But if I open and save the .txt file as itself, the squares vanish and the blank (or null) are is represented correctly.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZoppoCommented:
Could you post such a file with those  [] [] [] []  here?
0
 
NNiicckkAuthor Commented:
I cannot send the text file but a small reference.  The squares do not appear in the text file but when attempting to convert them in Monarch.  Once I save the file as itself, the issue is resolved.
squares.PNG
0
 
ZoppoCommented:
Hm - this doesn't help much. I thought with a sample file we could try to find a way to convert the file with some command line tools.

Generally I would say converting it by opening it in a text editor and anyhow make the text editor doing a 'Save As' is diffcult because I think it can only be done via GUI automation. If you really want to try it I'd suggest you take a look at AutoIt (http://www.autoitscript.com/site/autoit/), this is a scripting language with lots of possibilities to control other applications.

Anyway I would suggest to find a way to do it without using a text editor this way because with the text editor there might be problems with GUI automation, i.e. if while the file is open it might be any other application pops up and thus disturbs the automation script.

With such a sample file it would be easy to i.e. write a small VB script which can be called by your batch file, but without knowing what the original file-format is it's hard.
0
 
NNiicckkAuthor Commented:
OK, Thanks
0
 
NNiicckkAuthor Commented:
It was the best answer provided.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now