How do I assign the value of one variable to another variabl

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ptolemy
Posts: 2
Joined: 24 Apr 2012 19:27

How do I assign the value of one variable to another variabl

#1 Post by ptolemy » 24 Apr 2012 20:28

Hello all

I'm stuck on a very simple problem to which I have searched all over for an answer. No luck anywhere Googled high and low and searched this forum, all to no avail.

How does one put the value of one variable into another variable?

I have very little experience with batch files so I may be coming at this completely wrong. All corrections and suggestions gratefully accepted.

Here's the problem. I'm writing a script which:

launches Word 2007 with a file name derived from the current date.
The user writes his document then saves it as a PDF file and then exits Word.
Adobe reader is then launched so that he can examine the PDF file. He then exit's Reader.
He is then asked for a password. And then asked to enter the password again. The passwords are compared.
The PDF file is then encrypted using the console version of AES-Crypt.
Script checks for the existence of the encrypted file which will be called filename.pdf.aes and places a copy on the desktop. User can then attach and email.
Script then securely wipes both the Word and PDF file and keeps a copy of the aes file.

There are some options: Does the user want to go back and edit if he spots an error before encrypting? Does he want to save the Word file and come back to it later?

And there is the problem.

If there exists a Word file, he is asked if he would like to edit it. If not it is deleted (don't want multiple files accumulating).

The existing Word file name is put into a variable with this code:
for /F %%a in ('dir /b *.docx') do set xfileName=%%~na
There will never be more than one Word file in that directory.

The file name for a new set of files, Word and PDF, is derived this way:
set mydate=%DATE:~0,2%%DATE:~3,2%%DATE:~8,2%
set filename=PTPL%mydate%

If he starts a new file the file name will be %filename%
The existing file name will be %xfileName%

All the subroutines are set to work with %filename% so surely the simplest thing to do is put the value of %xfileName% into %filename% ?

So I said: set %filename%=%xfileName%

To my astonisment, it doesn't work. How can I do that?

All comment, suggestions and advice gratefully accepted.

Another less pressing problem: How can I mask password entry?

TIA

Harry

Edit:

I think I may have just answered my own question. I suppose I can just declare the %filenme% variable from scratch. Instead of getting its value from %mydate% it will get its value from %xfileName%

Will SET filename=%xfileName% overwrite the original?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How do I assign the value of one variable to another var

#2 Post by Fawers » 25 Apr 2012 04:05

SET filename=%xfileName% DOES overwrite %filename%. If you want %xfilename% to be part of %filename%, then you should do something like

Code: Select all

set filename=%filename% %xfilename%

or

Code: Select all

set filename=%xfilename% %filename%
.

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

Re: How do I assign the value of one variable to another var

#3 Post by foxidrive » 25 Apr 2012 08:12

double post
Last edited by foxidrive on 25 Apr 2012 08:14, edited 1 time in total.

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

Re: How do I assign the value of one variable to another var

#4 Post by foxidrive » 25 Apr 2012 08:13

So I said: set %filename%=%xfileName%


This will put the value of xfilename into the filename variable.

set filename=%xfileName%

ptolemy
Posts: 2
Joined: 24 Apr 2012 19:27

Re: How do I assign the value of one variable to another var

#5 Post by ptolemy » 25 Apr 2012 10:15

Thanks to foxdrive and Fawers for your responses.

That problem is now solved.

Apologies regarding double post, will take my masked password query to the appropriate thread.

Regards.

Harry

Post Reply