고유한 대상 폴더(windows)를 사용하여 특정 파일을 백업하는 배치 스크립트를 만드는 방법

고유한 대상 폴더(windows)를 사용하여 특정 파일을 백업하는 배치 스크립트를 만드는 방법

제가 좋아하는 오래된 게임(Fallout New Vegas 1.4.0.525)을 설정하려고 하는데, 이 게임은 저장 파일 손상으로 악명이 높습니다. 제가 묻고 싶은 것은 저장 파일을 복사하고 복사된 저장 파일을 특정 백업 저장 세트에 대한 폴더에 넣고 시간에 따라 폴더에 고유한 이름을 할당하는 배치 스크립트를 만드는 것이 가능한지입니다. 스크립트가 실행됩니다. 내 운영체제는 윈도우 10이다.

기본적으로 제가 도움을 구하는 과정은 다음과 같습니다.

Script started -> New Folder with a timestamp for name created -> save copied files to the new folder. 

제가 목표로 하는 타임코드에 대한 대략적인 아이디어는 HHDDMMYYYY(예: 1203042019)입니다.

스크립트를 복사하려는 저장 파일은 C:\Users-USER-\Documents\My Games\FalloutNV\Saves에 있으며, 백업 저장이 포함된 폴더는 F:\Backups에 있습니다. 복사가 필요한 저장 파일은 .fos 및 .nvse 파일 유형으로 제공됩니다(.fos는 게임의 저장 파일 유형이고 .nvse는 모드 구성을 위한 일반 저장 파일 외에 모드에서 생성한 저장 파일 유형입니다).

가능하다면 특정 프로그램(모드 관리자이자 실행 프로그램인 Vortex)을 열 때마다 스크립트가 실행될 수 있는지 알고 싶습니다.

미리 감사드립니다.

명확하게 편집됨

답변1

배치 파일이 아닌 PowerShell로 작성되었지만 플러그인이나 추가 기능 없이 Windows 10에서 기본적으로 작동합니다.

나는 아래와 비슷한 것이 당신이 추구하는 것이라고 믿습니다. 내 예에서는 시작하는 데 도움이 되도록 많은 설명을 포함하려고 노력했습니다. Powershell로 작성되었으므로 스크립트를 "myScript.ps1"로 저장한 다음 바탕 화면에 "PowerShell.exe -File C:\users\me\whereeverthescriptis\myScript.ps1"에 대한 바로가기를 만들어야 합니다.

백업을 시도하고 성공하면 앱을 실행합니다.

#What do you want to backup?
$sourceFolder = "C:\users\bbell\Desktop\p"
#Where do you want to backup to?
$destinationFolder = "C:\Installs"

#Figure out a destination folder with a timestamp.  Store it in a variable so that the same folder name is used throughout the script if it takes over a second to run
$destinationFolderWithTimestamp = ($destinationFolder + "\" + (Get-Date -Format yyyy-mm-dd_HH-mmmm-ss))

#if <destination folder>\<current date and time> doesn't exist - create it!
If (!(Test-Path -Path $destinationFolderWithTimestamp)) {
    New-Item -ItemType Directory -Path $destinationFolderWithTimestamp
    Write-Host ($destinationFolderWithTimestamp + " Created")
}

try {
    #try a backup - stop if it fails
    Copy-Item -Recurse -Path $sourceFolder -Destination $destinationFolderWithTimestamp -ErrorAction Stop -force
    #confirm backup worked
    Write-Host "Backup Completed OK"
    #launch an app - in this case notepad - the "&" needs to be kept as it denotes launching something
    & C:\Windows\notepad.exe
} catch {
    #Error happened - inform user and do not launch
    Write-Host "Backup Failed - not launching app"
}

관련 정보