Jump to content

Recommended Posts

Posted

In my text editor I created a script (text editor script language) to backup files like this:

p.e. mytextfile.txt -->

bkp_Filename without extension_Date_Time.extension

bkp_mytextfile_2014-12-19_10-23.txt

I was wondering if I could create a script in autoit to do this globally p.e. in word 2007, wordpad or whatever other text editor.

Maybe it is not so difficult to construct the backup name of the file but I don't have any idea how to capture the current filename of the document I'm currently editing.

Is there a way in autoit to know the current filename of a document?

Remin

ps: I wish everybody a happy new year!

Posted

_FilelistToArray will give you all the filenames in a current directory specified.

Happy new year!

Snips & Scripts

  Reveal hidden contents

My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted

Thank you Breathe,

Doesn't this list only files in a certain folder?

I would like to see a list of all open files in my text editors.

Posted
  Quote
Is there a way in autoit to know the current filename of a document?

Given the number of different text editors and the difficulty of identifying which file(s) are currently opened within each text editor, I don't think so.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted
  On 1/2/2015 at 9:35 PM, kylomas said:

Hey Breathe, what's up !?1?

 

Howdy kylosmas ^_^

Snips & Scripts

  Reveal hidden contents

My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Posted (edited)

I've created a small script to create a backup of the current word file:

#include <Word.au3>

HotKeySet("!5",  "_BkpWordDoc")

Func _BkpWordDoc()
   Global $oWord = _Word_Create()
   Global $oDoc = _Word_DocGet($oWord, 1)
   Local $myDocNam = StringRegExpReplace($oDoc.Name, ".doc*", "")
   Local $filetime = FileGetTime($oDoc.FullName, 0, 0)
   ;backup using actual time (bkp_filename_date_time.filextension)
   ; FileCopy($oDoc.FullName, "d:\bkp_" & $myDocNam & "_" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & ".doc", 1)
   ;backup using modified time (bkp_filename_date_time.filextension)
   FileCopy($oDoc.FullName, "d:\bkp_" & $myDocNam & "_" & $filetime[0] & "-" & $filetime[1] & "-" & $filetime[2] & "_" & $filetime[3] & "-" & $filetime[4] & ".doc", 1)
EndFunc

Maybe someone is interested in it.

Wish I could find a way to do this in all files p.e. .au3/txt/php/ini/py/doc*/xls* etc :)

Edited by remin
Posted

Updated version:

- backup also of .docx files.

#include <Word.au3> 

HotKeySet("!5",  "_BkpWordDoc")

Func _BkpWordDoc()
   Global $oWord = _Word_Create()
   Global $oDoc = _Word_DocGet($oWord, 1)

   Local $myDocName = StringRegExp($oDoc.Name, ".*(?=\.[a-zA-Z0-9]*$)", 1)
   Local $myDocExt  = StringRegExp($oDoc.Name, "\.[a-zA-Z0-9]*$", 1)
   Local $filetime  = FileGetTime($oDoc.FullName, 0, 0)

   ;backup using actual time
   ; FileCopy($oDoc.FullName, "d:\bkp_" & $myDocName[0] & "_" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & $myDocExt[0], 1)
   ;backup using modified time
   FileCopy($oDoc.FullName, "d:\bkp_" & $myDocName[0] & "_" & $filetime[0] & "-" & $filetime[1] & "-" & $filetime[2] & "_" & $filetime[3] & "-" & $filetime[4] & $myDocExt[0], 1)
EndFunc
Posted
  On 1/5/2015 at 2:25 PM, remin said:
Wish I could find a way to do this in all files p.e. .au3/txt/php/ini/py/doc*/xls* etc :)

Why are you just not using the file path with the FileCopy command?

Without too much trouble, you can do a backup copy of any file, even with an incremental file name, which is easily coded.

Don't know why you are even using Word to do any of this.

FileCopy allows you to rename, plus you can use date and time macros to be part of that renaming.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted
  On 1/7/2015 at 1:01 PM, TheSaint said:

Why are you just not using the file path with the FileCopy command? ....

FileCopy allows you to rename, plus you can use date and time macros to be part of that renaming.

 

That would be nice but can you please tell me how to find the path and the current filename of the file I'm editing?

Using FIleCopy I have to go to Windows Explorer, copy the filename and insert it in a input box invoked from the  backup_function, isn't it?

  • 2 weeks later...
Posted (edited)

#include <Word.au3> 

HotKeySet("!5",  "_BkpWordDoc")

Func _BkpWordDoc()
   Global $oWord = _Word_Create()
   Global $oDoc = _Word_DocGet($oWord, 1)

   Local $myDocName = StringRegExp($oDoc.Name, ".*(?=\.[a-zA-Z0-9]*$)", 1)
   Local $myDocExt  = StringRegExp($oDoc.Name, "\.[a-zA-Z0-9]*$", 1)
   Local $filetime  = FileGetTime($oDoc.FullName, 0, 0)

   ;backup using modified time
   FileCopy($oDoc.FullName, "d:\bkp_" & $myDocName[0] & "_" & $filetime[0] & "-" & $filetime[1] & "-" & $filetime[2] & "_" & $filetime[3] & "-" & $filetime[4] & $myDocExt[0], 1)
EndFunc

Once in a while I receive this error:

Local SmyDocName = StringRegExp($oDoc.Name, ".*(?=.[a-zA-Z0-9]*$)", 1)
Local SmyDocName = StringRegExp(SoDoc^ ERROR
Error: Variable must be of type "Object"
 
Does anybody know why?
Edited by remin
Posted (edited)
  On 1/7/2015 at 2:00 PM, remin said:

That would be nice but can you please tell me how to find the path and the current filename of the file I'm editing?

Using FIleCopy I have to go to Windows Explorer, copy the filename and insert it in a input box invoked from the  backup_function, isn't it?

Ok, didn't realize you were talking about a file you had open in Word and were working on.

Word has backup/save option.

But you are probably like me and don't like them.

In that case, you should be using Word Macros (VBA) to do what you want. No need for AutoIt at all. That's what I do. Use a button or menu item to run your VBA macro.

If you really need to, you can even use AutoIt to run that VBA macro ... see the Word UDF.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted (edited)

I want to create backups not only for word files, that's why I stick to autoit :)

But..

Again this error:

Local SmyDocName = StringRegExp($oDoc.Name, ".*(?=\.[a-zA-Z0-9]*$)", 1)
Local SmyDocName = StringRegExp(SoDoc^ ERROR
Error: Variable must be of type "Object"

Can't find the solution.

any idea?

Edited by remin
Posted (edited)

remin,

If your purpose is to do real time (or close to it) backups then check out >this thread.  However, if the data currency window is larger (you define what "larger" means in your context) then any incremental/differential scheme should work. 

Good Luck,

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted (edited)
  On 1/21/2015 at 12:01 AM, kylomas said:

Show the code where $oDoc is created...and re-read post #5...

 

Hi Kylomas,

Please see post#12

ps: Agree that there are many different editors. I'm sure I need more than one backup script in the future  :)

Edited by remin

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...