zoukankan      html  css  js  c++  java
  • 为促进工作效率写的小工具,公开源码

    最近有上千的图片,要追加到对应的目录(数以百计)里,而且没有规律可循。全手工操作,得让人头疼一个月,我以前这样追加过,不想再重复噩梦了。花了一天,写了这个工具。构思花了N天,我是新手。没想到,还写出来了。特发给热爱编程的业余新手朋友,希望对大家前进的路途助一把力。高手,就不要浪费时间来看了哈。

    功能介绍:

    将目录A中的1300张图,按textBox1中输入的(例如:输入0-3),则表示,将A目录中的第1至4共计4张图copy到B目录,并且这四张图的文件名,是接着B目录里的文件名顺序递增的(假设B目录中原有连续的39张图,名字为00000001.jpg,00000002.tif,00000003.gif...00000039.jpg ,扩展名,可以各不一样,那么这四张图的文件名在B目录中就为00000040.jpg,00000041.tif...00000043.gif--这四图的扩展名是按保留其原来的扩展名的。)

    描述得不太清楚,因为这是我繁复的工作,也正是因为此,我才写这工具来减轻工作痛苦的。

    以下是源码,用心的朋友,看源码,并作实验,相信会比看我前面的叙述更容易明白。

    http://ike.126.com

    =====

    using System;
    using System.Text;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;

    namespace copyjpg
    {
     /// <summary>
     /// Form1 的摘要说明。
     /// </summary>
     public class Form1 : System.Windows.Forms.Form
     {
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.TextBox textBox1;
      private System.Windows.Forms.TextBox textBox2;
      private System.Windows.Forms.TextBox textBox3;
      /// <summary>
      /// 必需的设计器变量。
      /// </summary>
      private System.ComponentModel.Container components = null;

      public Form1()
      {
       //
       // Windows 窗体设计器支持所必需的
       //
       InitializeComponent();

       //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }

      /// <summary>
      /// 清理所有正在使用的资源。原作者:花纯春
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null)
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }

      #region Windows 窗体设计器生成的代码
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改 原作者:花纯春
     /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {
       System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
       this.button1 = new System.Windows.Forms.Button();
       this.textBox1 = new System.Windows.Forms.TextBox();
       this.textBox2 = new System.Windows.Forms.TextBox();
       this.textBox3 = new System.Windows.Forms.TextBox();
       this.SuspendLayout();
       //
       // button1
       //
       this.button1.Location = new System.Drawing.Point(216, 120);
       this.button1.Name = "button1";
       this.button1.TabIndex = 0;
       this.button1.Text = "执行";
       this.button1.Click += new System.EventHandler(this.button1_Click);
       //
       // textBox1
       //
       this.textBox1.Location = new System.Drawing.Point(64, 48);
       this.textBox1.Name = "textBox1";
       this.textBox1.TabIndex = 1;
       this.textBox1.Text = "";
       //
       // textBox2
       //
       this.textBox2.Location = new System.Drawing.Point(112, 176);
       this.textBox2.Name = "textBox2";
       this.textBox2.TabIndex = 2;
       this.textBox2.Text = "源";
       //
       // textBox3
       //
       this.textBox3.Location = new System.Drawing.Point(112, 224);
       this.textBox3.Name = "textBox3";
       this.textBox3.TabIndex = 3;
       this.textBox3.Text = "目的";
       //
       // Form1
       //
       this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
       this.ClientSize = new System.Drawing.Size(292, 273);
       this.Controls.Add(this.textBox3);
       this.Controls.Add(this.textBox2);
       this.Controls.Add(this.textBox1);
       this.Controls.Add(this.button1);
       this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
       this.Name = "Form1";
       this.Text = "公告Copy工具";
       this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application.Run(new Form1());
      }

      public void fileop()
      {
       string[] filelists=Directory.GetFiles(@textBox2.Text);
       string[] filelistd=Directory.GetFiles(@textBox3.Text);
       string soo=textBox1.Text;
       string[] sss=soo.Split('-');
       int i1=Convert.ToInt32(sss[0]);
       int i2=Convert.ToInt32(sss[1]);
       int nmn=i2-i1;
       for(int i=0;i<=nmn;i++)
       {
        int indd=i1+i;
        int numm=filelistd.Length+i;
       
       
       
        string tailname=numm.ToString()+System.IO.Path.GetExtension(filelists[indd]);
       
       
       
        string ttt=tailname.PadLeft(12,'0');
       
        MessageBox.Show(ttt);
       

        File.Copy(filelists[indd],@textBox3.Text+@"\"+ttt,true);


       }

      }
      private void button1_Click(object sender, System.EventArgs e)
      {
       fileop();
      
      }
     }
    }
    // http://ike.126.com

    //欢迎转载


  • 相关阅读:
    在VS2010中如何添加MSCOMM控件,实现串口通讯
    GroupBox与Panel控件
    如何在VS2010中添加ActiveX控件及使用方法
    如何在vs2010中添加Picture控件
    四线开发经验谈
    socket 、 udp 和 tcp
    文本文件与二进制文件
    文件读写 (流)
    [CTSC1999]家园
    洛谷 P1251 餐巾计划问题
  • 原文地址:https://www.cnblogs.com/meta/p/meta.html
Copyright © 2011-2022 走看看