小编Kaz*_*oph的帖子

使用powershell批量设置变量

我一直在绞尽脑汁试图弄清楚这一点。

这段代码

@echo off
powershell $Yesterday = (get-date((get-date).addDays(-1)) -format yyyyMMdd)
echo %Yesterday%

::neither one of these echo anything

@echo off
powershell Set-Variable -Name "Yesterday" -Value (get-date((get-date).addDays(-1)) -format yyyyMMdd)
echo %Yesterday%
Run Code Online (Sandbox Code Playgroud)

都应该返回昨天日期的响应(格式为 yyyMMdd),但是,它们没有。使用 powershell,以下代码确实有效并返回正确的响应:

$Yesterday = (get-date((get-date).addDays(-1)) -format yyyyMMdd)
Write-Host $Yesterday

::Both of these work in powershell

Set-Variable -Name "Yesterday" -Value (get-date((get-date).addDays(-1)) -format yyyyMMdd)
Write-Host $Yesterday
Run Code Online (Sandbox Code Playgroud)

但批量使用时不起作用。有什么想法吗?我试图设置该变量%Yesterday%以便稍后在脚本中使用它,但它的行为并不像我预期的那样。我确信它很简单,但我现在还不知道它是什么。

类似的问题

powershell batch-file environment-variables powershell-2.0

4
推荐指数
1
解决办法
676
查看次数

将文件拖入富文本框以读取文件中的文本

我在将文件拖放到 richTextBox 上时遇到问题,每次将文本文件拖到其上时,它都会变成文本文件的图片,其名称位于其下方。双击该文件,它会使用系统默认应用程序(即用于文本文件的记事本等)打开。基本上,当我希望它读取文件中的文本时,它会在 richTextBox 中创建快捷方式。

根据此代码,文件中的文本提取到 richTextBox1 中

    class DragDropRichTextBox : RichTextBox
    {
    public DragDropRichTextBox()
    {
        this.AllowDrop = true;
        this.DragDrop += new DragEventHandler(DragDropRichTextBox_DragDrop);
    }

    private void DragDropRichTextBox_DragDrop(object sender, DragEventArgs e)
    {
        string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];

        if (fileNames != null)
        {
            foreach (string name in fileNames)
            {
                try
                {
                    this.AppendText(File.ReadAllText(name) + "\n");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

关于如何实现这项工作有什么想法吗?

.net c# drag-and-drop richtextbox text-files

1
推荐指数
1
解决办法
8128
查看次数