Can anyone help me with a python script I'm writing to change a password in a batch file.

I need to replace the old password with the new one.
I can do this by getting the old password from the user by raw.input, but I'd really like to just replace the existing password in the file.

It's in the format -s"password" where the -s and "" remain constant, but the password bit changes, with variable length and content (incl spaces).

In windoze you'd just use -s"*" but the python wild card . seems only to represent 1 character.

Alternatively, I could test the raw.input password against the bit between the " " and keep asking for the old password until the user inputs the correct one. But this is beyond my current knowledge of python!

The final option would be to get the old password from a log file. I'm appending the previous new password (which becomes the old password at the next iteration)and the date of change as the last line of a log file.

Any help in pursuing these options gratefully received!

Thanks,

William

You can also use the var.find("-s") method for strings and then slice it. It depends on if -s"password" is the only thing in that record or not.

Thanks, I've done it using

newfile1 = re.sub(r'-s".*?"', textToReplaceWith, oldfile1)

William

This question has already been answered. Start a new discussion instead.