基于文本文件作为标识符的构建菜单 [英] Building Menu Based on Text Files as Identifiers

查看:84
本文介绍了基于文本文件作为标识符的构建菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户决定切换时,我希望对我的批处理文件进行智能化处理,以不将当前数据库包含在菜单中-看起来有些愚蠢,无法选择您正在使用的东西.

I am looking to smarten up my batch file to NOT include the current database in the menu when the users decides to switch -looks a bit silly to chose something you are already using.

该脚本在workdir路径中扫描文本文件,并将它们用作软件不同配置的标识符.它替代了软件的标准快捷方式,因此客户端可以选择他们想要连接的位置-或继续使用当前"配置.

The script scans for text files in the workingdir path and uses them as identifiers for different configurations of the software. It replaces the standard shortcut for the software so the client can choose where they want to connect to - or carry on with the 'current' configuration.

这一切都完全符合我的要求,只是使它在客户看来更聪明.

It all does exactly as I want it's just making it a bit smarter with regards to how it appears to the customers.

在用于访问其他数据库的软件中,您只需将工作目录的内容替换为另一个工作目录的内容,但将其配置指向其他地方即可.当您切换当前设置时,会将其备份到具有自己名称的特殊目录中,然后将另一个复制到其自己的目录中并覆盖当前的工作目录.

Within the software to access a different database you just overwrite the workingdir contents with contents of another workingdir but with configs to point somewhere else. When you switch the current set up is backed up to a special directory of its own name, then the other is copied out of its own dir and overwrites the current working dir.

我希望做的是(希望地)进行一些调整,这些调整将向用户显示他们正在使用什么配置,如果他们决定切换为不",则将当前的作为选择.

What I am after is (hopefully) some adjustments that will show the user what configuration they are using and if they decided to Switch 'NOT' see the current one as a choice.

现在会发生什么&很好,但是很笨拙,它将告诉他们他们正在使用哪个数据库

What happens now & its fine, but it is clunky, it will tell them what database they are using

您正在使用Essex_Medical数据库 继续(1)或切换(2)

you are using Essex_Medical Database continue (1) or Switch (2)

如果他们进行切换,他们可以选择其他选项,但仍然可以选择当前的选项,我认为这对客户来说是草率的.

if they switch they can choose the other option BUT still gives the choice of the current one which I think will look sloppy to the customer.

切换到Essex_Medical数据库1 切换到纽卡斯尔医疗2 继续(1)(2)

switch to Essex_Medical Database 1 switch to Newcastle Medical 2 continue (1) (2)

我去了,但我的大脑迷糊了.我想我需要进行扫描以通过可用的文本文件来识别选择,从变量设置输入菜单,并从输入切换选项中忽略当前正在使用的菜单,我希望这样做有意义吗?这是代码...

I had a go but my brain fogged up. I think I need a scan to identify the choices via the available text files, set up the input menu from variables and the current one in use be omitted from the input switch options, I hope that makes sense?? Here is the code...

@echo off
color 8b
mode con: cols=80 lines=30
title Multi Database Switcher

rem setting working dir variable
set progdata=C:\ProgramData\Company\WorkingDir

cd %progdata%

for /r %%a in (*.txt) do (
rem spdir 'special directory to hold client specific config file & 
rem folders'
set spdir=C:\ProgramData\Company\%%~na
set current=%%~na
)

:menu
CLS
echo.
echo                    --------------------------------------------------
echo                    [1] -- Continue Using %current%'s DataBase
echo                    --------------------------------------------------
echo.
SET /P "Input=Continue(1)/Switch to Another Database(2):"
if '%Input%'=='1' goto continue
if '%Input%'=='2' goto menu2
goto :menu
:menu2
CLS
echo.
echo                    --------------------------------------------------
echo                    [2] -- Switch to the 'Essex_Medical' Database
echo                    [3] -- Switch to the 'Newcastle_Surgery' Database
echo                    --------------------------------------------------
ECHO.
echo Choose a number...
echo.
SET /P "Input=(2)/(3):"
if '%Input%'=='2' goto Essex_Medical
if '%Input%'=='3' goto Newcastle_Surgery
goto :menu2

:continue
start "" "C:\Temp\Shortcut.lnk" & exit

:Essex_Medical
robocopy %progdata% %spdir% /MIR >nul 2>&1 & robocopy C:\ProgramData\Company\Essex_Medical %progdata% /MIR >nul 2>&1
start "" "C:\Temp\Shortcut.lnk" & exit

:Newcastle_Surgery
robocopy %progdata% %spdir% /MIR >nul 2>&1 & robocopy C:\ProgramData\Company\Newcastle_Surgery %progdata% /MIR >nul 2>&1
start "" "C:\Temp\Shortcut.lnk" & exit

编辑清楚

软件程序使用一组文件夹&在一个位置c:\ programdata \ company \ workingdir中的配置文件.在workingdir中,有3或4个子文件夹&一个cfg文件.它们包含有关使用哪个数据库的软件信息.

edit for clarity

software program uses a set of folders & a config file in one location c:\programdata\company\workingdir. In workingdir there are 3 or 4 subfolders & one cfg file. They contain info for the software as to what database to use.

我有一个客户想要访问其他数据库,可以通过用不同的文件夹集和配置文件(具有相同的名称等)用不同的数据库详细信息等覆盖工作目录的内容来轻松实现.

I have a client who wants to access other databases, its easily done by over writing the contents of workingdir with a different folder set and config file (all same name etc) with different database details etc.

为便于切换,我的脚本使用了workdir中的文本文件来标识不同的数据库,通常是其他手术essex_surgery,newcastle_surgery,以便当用户启动脚本时,它告诉Workingdir他们使用的数据库就是您正在使用的数据库从所谓的文本文件.他们可以继续或切换.当他们切换时,当前的工作目录将备份到一个单独的文件夹,如果需要将其切换回该文件夹,则可以将其调出.它只是将当前的镜像复制到一个命名的文件夹,然后覆盖选定的文件夹集.

To facilitate switching my script uses a text file in the workingdir to identify the different databases usually other surgeries essex_surgery , newcastle_surgery so that when the user fires up the script it tells them from the workingdir you ARE using what ever the database is just from what the text file is called. They can continue or switch. When they switch the current working dir is backed up to a separate folder ready to be recalled if its needs to be switched back. Its just robocopy mirroing current to a named folder and over writing with chosen folder set.

我的牛肉是,当您切换时,当前数据库被选择切换到它,并且看起来很傻,为什么选择已经在使用的东西.

My beef is, when you switch, the current database is choice to switch to and its looks silly, why choose something you are already using.

推荐答案

也许我们用这样的数组填充:

Perhaps if we populate with an array like this :

@echo off
color 8b
mode con: cols=80 lines=30
title Multi Database Switcher

rem setting working dir variable
set "progdata=C:\ProgramData\Company\WorkingDir"

cd "%progdata%"
setlocal enableDelayedExpansion
for /r %%a in (*.txt) do (
rem spdir 'special directory to hold client specific config file & 
rem folders'
rem Populate the array with existent files
set /a idx+=1
set "spdir[!idx!]=C:\ProgramData\Company\%%~na"
set "current[!idx!]=%%~na"
)

:menu
CLS
rem Display array elements 
echo                    --------------------------------------------------
for /L %%i in (1,1,%idx%) do (
    set "msg=[%%i] - !current[%%i]!"
echo.
echo                       !msg!
echo.
echo                    --------------------------------------------------
)

echo(
echo  Please choose a number to continue ...
set /p "Input="
For /L %%i in (1,1,%idx%) Do (
    If "%INPUT%" EQU "%%i" (
        echo robocopy "%progdata%" "!spdir[%%i]!" /MIR 
        rem >nul 2>&1 & 
        echo robocopy "!spdir[%%i]!" "%progdata%" /MIR
rem     )>nul 2>&1
        echo start "" "C:\Temp\Shortcut.lnk" & pause 
        rem & exit
    )
)  
goto :menu

这篇关于基于文本文件作为标识符的构建菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆