Create and copy a file in a datestamp folder Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Luis Diaz
Posts: 28
Joined: 04 Jun 2020, 16:56

Create and copy a file in a datestamp folder

21 Jun 2020, 13:04

Hello,

I have the following:

Code: Select all

KFileA:=A_MyDocuments . "\1\AK.xlsx"
KFileB:=A_MyDocuments . "\2\BK.xlsx"

If (FileExist(KFileA))
  Run,%KFileA%
Else
If (FileExist(KFileB))
  Run,%KFileB%
Else
  MsgBox,4112,Error,Neither K file exists on your system
Return
Prior to the Run action I would like :
1.Check a Backup folder at KFile location if not create it.
Example: =A_MyDocuments . "\1\Backups"
2.Inside of this Backup folder create a datestamp folder: Example: A_MyDocuments . "\1\Backups\20200621_200237"
3.Copy KFile inside this folder.

Thank you in for your help.
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Create and copy a file in a datestamp folder  Topic is solved

22 Jun 2020, 03:48

This should do what you need

Code: Select all

KFileA := A_MyDocuments . "\1\AK.xlsx"
KFileB := A_MyDocuments . "\2\BK.xlsx"

if !Backup(KFileA)
	if !Backup(KFileB)
		MsgBox,4112,Error,Neither K file exists on your system
Return

Backup(file,runFile=1) {  ;runFile is a default parameter, if not supplied defaults to 1
	ifnotexist,% file
		return 0
	SplitPath,file,fileName,filePath  ;split the file path to get it's name and directory
	
	BackupPath := filePath "\backups"
	timeStampPath := BackupPath "\" a_now  ;a_now is a built in variable that contains YYYYMMDDHHMMSS
	
	IfNotExist,% BackupPath
		FileCreateDir,% BackupPath
	IfNotExist,% timeStampPath
		FileCreateDir,% timeStampPath
	
	filecopy,% file,% timeStampPath "\" fileName
	
	if (runFile) { ;if the function is called with runFile it will run the file after backing up
		run, % file
	}
	
	return 1
}
Luis Diaz
Posts: 28
Joined: 04 Jun 2020, 16:56

Re: Create and copy a file in a datestamp folder

28 Jun 2020, 12:45

Tested and it works!

Thank you very much for your help!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 64 guests