C
C
Cavabanga2020-12-09 13:34:32
PowerShell
Cavabanga, 2020-12-09 13:34:32

Folder Copy Script?

Good afternoon comrades. I don't know much about cmd and/or powershell. The question arose - there are clean templates of file bases 1c (PROF, CORP, Basic) always lie in the same place, conditionally in d:\clean bases\prof d:\clean bases\corp, etc. Sometimes accountants need to make a new clean database (whether professional or corporate), this is done by simply copying the folder with the blank and then renaming it to the name of the organization.
That is, a script similar to - robocopy "d:\clean bases\prof" "d:\base\ooo horns and hooves" /E - showed itself perfectly. It essentially replaces copy/paste/rename. Is it possible to remake it somehow so that it first issues a request ala: "Do you need COPR, PROF or basic?", three buttons on the screen, after selecting the desired user, the script would select the desired directory. The second request: "How to name the new folder?", here, respectively, the field where the user will enter the name of the new organization. Then the copying takes place.
Or do I want too much?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
res2001, 2020-12-09
@res2001

The input can be made using the construction:
set /p val="Как назвать новую папку?: "
The variable val will contain the string entered by the user.

A
alhaos, 2020-12-14
@alhaos

<#
.SYNOPSIS
    a script that creates a folder and copies another folder into it depending on the user's choice
.PARAMETER clearCorpDatabaseDirecoryName
    directory name which contains clear Corporate database.
.PARAMETER clearProfDatabaseDirecoryName
    directory name which contains clear Professional database.
.PARAMETER clearBasicDatabaseDirecoryName
    directory name which contains clear Basic database.
.PARAMETER databaseDirecoryName
    Specifies the directory where will be created new directory.
#>

param (
    [System.IO.DirectoryInfo]$clearCorpDatabaseDirecoryName = "d:\чистые базы\корп",
    [System.IO.DirectoryInfo]$clearProfDatabaseDirecoryName = "d:\чистые базы\проф",
    [System.IO.DirectoryInfo]$clearBasicDatabaseDirecoryName = "d:\чистые базы\базовая",
    [System.IO.DirectoryInfo]$databaseDirecoryName = "D:\tmp"
)

enum DatabaseEdition {
    corp = 0
    prof = 1
    basic = 2
}

try {
    [String]$companyName = Read-Host -Prompt "Enter company name"
    [DatabaseEdition]$userChoice = Read-Host -Prompt "Select database type 0 - corp, 1 - prof or 2 - basic"

    $companyDirectory = New-Item -ItemType Directory -Path (Join-Path $databaseDirecoryName -ChildPath $companyName)
    switch ($userChoice){
        corp {
            Write-Host "User choice corporate"
            Copy-Item $clearCorpDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
            "Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName

        }
        prof {
            Write-Host "User choice professional"
            Copy-Item $clearProfDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
            "Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
        }
        basic {
            Write-Host "User choice basic"
            Copy-Item $clearBasicDatabaseDirecoryName -Destination $companyDirectory.FullName -Recurse
            "Directory {0} directory copied to {1}" -f $clearCorpDatabaseDirecoryName, $companyDirectory.FullName
        }
    }
}
catch {
    Write-Host "An error occurred:"
    Write-Host $_
}

C
Cavabanga, 2021-01-22
@Cavabanga

The script above partially works. The folder is created on the desired path, only empty (Essno changed to my directories).
On startup it gives the following error:
600aa0b3e80fd450702503.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question