在DOS 6.22中创建提示用户输入文件路径的批处理文件

时间:2017-11-09 16:46:18

标签: batch-file dos

我正在尝试在DOS 6.22中创建一个.BAT文件,它将A:中的软盘内容复制到C:\,然后将创建的文件夹设置为系统变量。我尝试使用类似“SET / P VARIABLE =输入路径”之类的东西,但DOS只会添加“/ P VARIABLE”作为变量,其值为“输入路径”,因此使用/ P isn这是一个选项,因为/ P不是DOS 6.22中的开关

我尝试使用像for循环这样的东西来设置一个变量到文件但是我遇到一个减速带是我不知道该文件夹将在驱动器A:\中调用什么,因为它会改变所有的时间,但只包含一个文件夹,所以基本上我只是想找到一种方法将驱动器A中找到的第一个目录复制到C:\并将其设置为系统变量。一旦用户完成更改,我将不得不将该文件夹复制回A:\并覆盖旧文件,以便在进行更改后将其存储在网络上。

我尝试通过.BAT文件尝试一些If / for语句,但我没有太多运气,如果有人能指出我正确的方向,那将是非常棒的。

此时我可能比这更复杂。

3 个答案:

答案 0 :(得分:0)

我在从@Squashman链接的更多研究中找到了解决方案。事实证明,通信中断了,这甚至不是用户的原始问题(一种简单的方法将文件复制到A:\以及所有这些)

我使用了以下内容。

 echo Type "set myvar="name of the folder" replacing name of the folder with 
 echo the name of the folder containing the files on A:\ example if you were 
 echo  on "example" you would type: set myvar=example      
 copy con answer.bat
 echo Type the words "set myvar=" (don't type the quote marks)
 echo and then immediately after the = sign, press Control-Z then enter
 call answer.bat
 mkdir C:\%myvar%
 xcopy A:\%mvar% C:\%myvar%
 DEL answer.bat

这是我在此处找到的指南的修改版本。 http://www.pement.org/sed/bat_env.htm#4dos

希望这能够帮助某些人,这在任何想象中都不是很漂亮,但它有效。

答案 1 :(得分:0)

这样的事情也应该起作用:

 @echo off
 :INPUT.BAT puts what is typed next in environment variable INPUT
 set input=
 echo INPUT.BAT
 echo Type in something and press [Enter]
 fc con nul /lb1 /n|date|find "    1:  ">temptemp.bat
 echo :Loop>>enter.bat
 echo if not (%%input%%)==() set input=%%input%% %%5>>enter.bat
 echo if (%%input%%)==() set input=%%5>>enter.bat
 echo shift>>enter.bat
 echo if not (%%5)==() goto Loop>>enter.bat
 for %%x in (call del) do %%x temptemp.bat
 del enter.bat
 echo The string you just entered:
 echo %input%
 echo has been stored in an environment variable named INPUT
 :End

答案 2 :(得分:0)

我认为如果用户实际上只需要复制一个目录,这对用户来说会更容易。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace StoreProcedureExample
{
    public partial class Form1 : Form
    {
        SqlConnection conn = new SqlConnection("Data Source=DESKTOP-S80LS9D;Initial Catalog=ComboBoxTest;Integrated Security=True");
        SqlCommand cmd;
        SqlDataAdapter data;
        DataSet ds;
        int num = 0;
        int i;

        public Form1()
        {
            InitializeComponent();
            cmd = new SqlCommand("UserInformation", conn);
            data = new SqlDataAdapter(cmd);
            ds = new DataSet();
            data.Fill(ds);
            this.userdataGridView1.DataSource = ds.Tables[0];
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            SaveRecord();
            ShowRecordAfterSaveAndEdit();
            clearfilds();
        }

        public void SaveRecord()
        {
            cmd = new SqlCommand("insertupdate", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            if (userTextBox.Text == "")
            {
                num = 0;
            }
            else
            {
                num = int.Parse(userTextBox.Text);
            }
            cmd.Parameters.AddWithValue("@id", num);
            cmd.Parameters.AddWithValue("@name", nameTextBox.Text);
            cmd.Parameters.AddWithValue("@PhoneNumber", phoneNumberTextBox.Text);
            if (saveButton.Text == "Save")
            {
                cmd.Parameters.AddWithValue("@Flag", 'S');
            }
            else
            {
                cmd = new SqlCommand("UpdateUser", conn);
                cmd.CommandType = CommandType.StoredProcedure;
            }

            try
            {
                conn.Open();
                if (cmd.ExecuteNonQuery() > 0 && saveButton.Text == "Save")
                {
                    MessageBox.Show("record inserted");
                }
                else
                {
                    MessageBox.Show("record Update");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                conn.Close();
            }
        }

        public void clearfilds()
        {
            userTextBox.Text = "";
            nameTextBox.Text = "";
            phoneNumberTextBox.Text = "";
            saveButton.Text = "Save";
        }

        public void ShowRecordAfterSaveAndEdit()
        {
            cmd = new SqlCommand("UserInformation", conn);
            data = new SqlDataAdapter(cmd);
            ds = new DataSet();
            data.Fill(ds);
            this.userdataGridView1.DataSource = ds.Tables[0];
            conn.Close();
        }

        private void ShowData(object sender, EventArgs e)
        {
            int show = userdataGridView1.CurrentRow.Index;
            userTextBox.Text = userdataGridView1.CurrentRow.Cells["Id"].Value.ToString();
            nameTextBox.Text = userdataGridView1.CurrentRow.Cells["Name"].Value.ToString();
            phoneNumberTextBox.Text = userdataGridView1.CurrentRow.Cells["PhoneNumber"].Value.ToString();
        }
    }
}
相关问题