我通过Windows制作脚本相当新。也许我甚至需要一些脚本以外的东西。我使用带有csv文件的sed在linux中做了一些类似的事情,但是我想制作一个.bat脚本文件(或类似的东西),它会占用ac头文件并删除所有尾随空格。
编辑原因:(我的Svn repo不允许尾随白色空格,当使用C ++ UI表单时,每次添加新对象时都会添加带有尾随空格的注释,例如按钮)
编辑: 这些评论发生在以下所示的评论之后
"//
// outputStringsTab
// "
示例snippit:
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->tabCollection = (gcnew System::Windows::Forms::TabControl());
this->outputStringsTab = (gcnew System::Windows::Forms::TabPage());
this->justificationComboBox = (gcnew System::Windows::Forms::ComboBox());
this->stringSizeDropBox = (gcnew System::Windows::Forms::ComboBox());
this->stringFontLabel = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->stringSizeLabel = (gcnew System::Windows::Forms::Label());
this->stringBackgroundLabel = (gcnew System::Windows::Forms::Label());
this->fontCheckListBox = (gcnew System::Windows::Forms::CheckedListBox());
this->greenRadio = (gcnew System::Windows::Forms::RadioButton());
this->blueRadio = (gcnew System::Windows::Forms::RadioButton());
this->whiteRadio = (gcnew System::Windows::Forms::RadioButton());
this->blackRadio = (gcnew System::Windows::Forms::RadioButton());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->shapePage = (gcnew System::Windows::Forms::TabPage());
this->circleAngleGroupBox = (gcnew System::Windows::Forms::GroupBox());
this->circleAngleLabel = (gcnew System::Windows::Forms::Label());
this->circleAngleStartTextBox = (gcnew System::Windows::Forms::TextBox());
this->circleAngleEndTextBox = (gcnew System::Windows::Forms::TextBox());
this->circleAngleButton = (gcnew System::Windows::Forms::Button());
this->startAngleLabel = (gcnew System::Windows::Forms::Label());
this->degreesLabel2 = (gcnew System::Windows::Forms::Label());
this->endAngleLabel = (gcnew System::Windows::Forms::Label());
this->degreesLabel1 = (gcnew System::Windows::Forms::Label());
this->lineSuppresionGroupBox = (gcnew System::Windows::Forms::GroupBox());
this->squareLineLabel = (gcnew System::Windows::Forms::Label());
this->noneSuppressRadio = (gcnew System::Windows::Forms::RadioButton());
this->topSuppressRadio = (gcnew System::Windows::Forms::RadioButton());
this->bottomSuppressRadio = (gcnew System::Windows::Forms::RadioButton());
this->leftSuppressRadio = (gcnew System::Windows::Forms::RadioButton());
this->rightSuppressRadio = (gcnew System::Windows::Forms::RadioButton());
this->sizeGroupBox = (gcnew System::Windows::Forms::GroupBox());
this->circleRadioButton = (gcnew System::Windows::Forms::RadioButton());
this->shapesHeightWidthLabel = (gcnew System::Windows::Forms::Label());
this->squareRadioButton = (gcnew System::Windows::Forms::RadioButton());
this->heightTextBox = (gcnew System::Windows::Forms::TextBox());
this->heightLabel = (gcnew System::Windows::Forms::Label());
this->sizeSendButton = (gcnew System::Windows::Forms::Button());
this->widthLabel = (gcnew System::Windows::Forms::Label());
this->widthTextBox = (gcnew System::Windows::Forms::TextBox());
this->gaugeTabPage = (gcnew System::Windows::Forms::TabPage());
this->gaugeValueGroupBox = (gcnew System::Windows::Forms::GroupBox());
this->barValueRadioButton = (gcnew System::Windows::Forms::RadioButton());
this->label5 = (gcnew System::Windows::Forms::Label());
this->meterValueRadioButton = (gcnew System::Windows::Forms::RadioButton());
this->label6 = (gcnew System::Windows::Forms::Label());
this->arcValueRadioButton = (gcnew System::Windows::Forms::RadioButton());
this->gaugeValueTrackBar = (gcnew System::Windows::Forms::TrackBar());
this->trackBarLabel = (gcnew System::Windows::Forms::Label());
this->tabCollection->SuspendLayout();
this->outputStringsTab->SuspendLayout();
this->shapePage->SuspendLayout();
this->circleAngleGroupBox->SuspendLayout();
this->lineSuppresionGroupBox->SuspendLayout();
this->sizeGroupBox->SuspendLayout();
this->gaugeTabPage->SuspendLayout();
this->gaugeValueGroupBox->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->gaugeValueTrackBar))->BeginInit();
this->SuspendLayout();
//
// tabCollection
//
this->tabCollection->Controls->Add(this->outputStringsTab);
this->tabCollection->Controls->Add(this->shapePage);
this->tabCollection->Controls->Add(this->gaugeTabPage);
this->tabCollection->Location = System::Drawing::Point(12, 12);
this->tabCollection->Name = L"tabCollection";
this->tabCollection->SelectedIndex = 0;
this->tabCollection->Size = System::Drawing::Size(827, 396);
this->tabCollection->TabIndex = 0;
//
// outputStringsTab
//
this->outputStringsTab->BackColor = System::Drawing::Color::White;
this->outputStringsTab->Controls->Add(this->justificationComboBox);
this->outputStringsTab->Controls->Add(this->stringSizeDropBox);
this->outputStringsTab->Controls->Add(this->stringFontLabel);
this->outputStringsTab->Controls->Add(this->label7);
this->outputStringsTab->Controls->Add(this->stringSizeLabel);
this->outputStringsTab->Controls->Add(this->stringBackgroundLabel);
this->outputStringsTab->Controls->Add(this->fontCheckListBox);
this->outputStringsTab->Controls->Add(this->greenRadio);
this->outputStringsTab->Controls->Add(this->blueRadio);
this->outputStringsTab->Controls->Add(this->whiteRadio);
this->outputStringsTab->Controls->Add(this->blackRadio);
this->outputStringsTab->Controls->Add(this->label4);
this->outputStringsTab->Controls->Add(this->label3);
this->outputStringsTab->Controls->Add(this->label2);
this->outputStringsTab->Controls->Add(this->label1);
this->outputStringsTab->Location = System::Drawing::Point(4, 22);
this->outputStringsTab->Name = L"outputStringsTab";
this->outputStringsTab->Padding = System::Windows::Forms::Padding(3);
this->outputStringsTab->Size = System::Drawing::Size(819, 370);
this->outputStringsTab->TabIndex = 0;
this->outputStringsTab->Text = L"Output Strings";
//
// justificationComboBox
//
this->justificationComboBox->FormattingEnabled = true;
this->justificationComboBox->Items->AddRange(gcnew cli::array< System::Object^ >(3) { L"Left", L"Middle", L"Right" });
......等等。
答案 0 :(得分:0)
Windows批处理脚本不提供图灵完整的编程语言,主要用于名称所暗示的内容 - 将多个命令(您可以从命令行执行)批处理。现代Windows确实提供了大量的MS-DOS批处理文件扩展,但它仍然不是一个适合你所要求的工具。
Windows现在包含PowerShell作为基本命令行处理器和批处理文件的替代方法;你可能会更好地使用它,但是你认为你可能使用C和C ++会很简单,用你熟悉的语言编写你自己的实用工具吗?
答案 1 :(得分:0)
<强> TrimSpace 强>
filter ts {l|r|lr|lc count}
修剪一行上的前导和尾随空格。
l - 删除前导空格。
r - 删除尾随空格。
lr - 删除前导和尾随空格。
lc - 删除
<count>
个前导空格。
示例强>
修复win.ini,而不是需要修复,并将其发送到屏幕
filter trimspace lc 5 <"%systemroot%\win.ini"
vbs脚本
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
If LCase(Arg(1)) = "l" then
Do Until Inp.AtEndOfStream
Line=Inp.readline
outp.writeline LTrim(Line)
Loop
ElseIf LCase(Arg(1)) = "r" then
Do Until Inp.AtEndOfStream
Line=Inp.readline
outp.writeline RTrim(Line)
Loop
ElseIf LCase(Arg(1)) = "lr" then
Do Until Inp.AtEndOfStream
Line=Inp.readline
outp.writeline Trim(Line)
Loop
ElseIf LCase(Arg(1)) = "lc" then
Count = Cint(LCase(Arg(2)))
Do Until Inp.AtEndOfStream
Line=Inp.readline
If Left(Line,Count) = Space(Count) then
outp.writeline Mid(Line, Count +1)
Else
outp.writeline LTrim(Line)
End If
Loop
End If
使用批处理文件启动它
cscript //nologo <pathtovbsscript\vbsscript.vbs> lc 5 <file.h
一般用途
过滤器用于命令提示符。必须使用cscript.exe运行Filter.vbs。如果您只是输入过滤器,它将运行一个自动执行此操作的批处理文件。
filter subcommand [parameters]
仅对标准输入和标准输出进行读写。这些仅在命令提示符中可用。
filter <inputfile >outputfile
filter <inputfile | other_command
other_command | filter >outputfile
other_command | filter | other_command