C#实战—代码实现收发文件智能化

在信息化的今天,收发电子文档几乎是每个朋友都要经历的事情。比如班级学委和班长需要收发作业,企业管理者需要收发工作文件。但是!!!

每到要交结果时,往往会发现总会有一些人没有即使交上,50个人的班级却只有48份文件,此时估计是很多学委和管理者的恶梦吧,大多数时候,我们只能对照名单一个一个检查,看看有那位小可爱不交作业,但是这样效率太低了,关键是,它真的真的很烦,尤其我是喜欢"偷懒"

最近收作业被反复折磨的我,决定未来的几年学委,我不要这么累,自己学了一点点编程,为什么不尝试写几行代码,让计算机这个苦力去干活呢?

于是写了下面的小程序!

基本思路

第一步:写入班级(集体)的名单,用txt文件存储

第二步:将收到的作业存入任意一个文件夹

第三步:利用文件名和名单对比,设计简单算法,找出,不交作业的小可爱。

华丽分割线............................................................

第一步:存储班级名单

第二步:将收到的文件存放在任意文件夹(大家应该都会吧^-^)

第三步:打开VS,写下如下代码(不同的文件路径名需要修改部分代码)

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace File_pracsice
{
    class Program
    {
        static void Main(string[] args)
        {
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"E:\Adan的文档\辩论文档");
            List<string> arraysd = new List<string>();//收到的作业array
            List<System.IO.FileInfo> allFile= GetAllFileInfo(dir);
            foreach (System.IO.FileInfo file in allFile)
            {
                arraysd.Add(file.Name);              
            }
            //Console.ReadLine();
            //string str1 = Console.ReadLine();
            //string[] array = str1.Split(',');

            string sFilename = "E:\\C#编程练习\\File pracsice\\File pracsice\\bin\\Debug\\students.txt";
            System.IO.FileStream afile = new System.IO.FileStream(sFilename, System.IO.FileMode.Open);
            StreamReader sr = new StreamReader(afile);
            string strline = sr.ReadToEnd();
            string[] arrayall = strline.Split(',');//班级总名单
            List<string> arraynew = new List<string>();
            for (int i = 0; i < arrayall.Length; i++)
            {
                string temp=arrayall[i].Remove(arrayall[i].Length - 2, 2);
                arraynew.Add(temp);
            }

            printf();
            for (int i = 0; i < arrayall.Length; i++)
            {
                for (int j = 0; j < arraysd.Count; j++)
                {
                    if (arraynew[i] == arraysd[j])
                    {
                        break;
                    }
                    else
                    {
                        if (arraynew[i] != arraysd[j] && j == arraysd.Count - 1)
                        {
                            Console.WriteLine(arraynew[i] );
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            Console.ReadLine();
        }
        public static void printf()
        {
            Console.WriteLine("班级总数共有25人,没交作业的有:");
        }

        public static List<System.IO.FileInfo> GetAllFileInfo(System.IO.DirectoryInfo dir)
        {
            List<System.IO.FileInfo> FileList = new List<System.IO.FileInfo>();
            System.IO.FileInfo[] allFile = dir.GetFiles();
            foreach (System.IO.FileInfo file in allFile)
            {
                FileList.Add(file);
            }
            System.IO.DirectoryInfo[] allDir = dir.GetDirectories();
            foreach (System.IO.DirectoryInfo d in allDir)
            {
                GetAllFileInfo(d);
            }
            return FileList;
        }
    }
}

最后的结果:(这两个人的名字是我乱编的了啦)原来是这两个小可爱没交如果有哪位小伙伴兴趣,欢迎私信小编哦。

今天的分享到这里就结束啦,希望对大家日常的工作有帮助,谢谢大家!

相关推荐
宽海智能仓储物流11 分钟前
航发自动化立体库异构系统改造:宽海智能30天联调技术全解析
运维·数据仓库·自动化
鹤落晴春19 分钟前
【K8s】从 ConfigMap 到 Argo CD:Kubernetes 配置管理链路
运维·云原生·容器·kubernetes
2601_9494999421 分钟前
DT‑1414PTZ如何百分百兼容(安华高)HFBR‑1414PTZ
运维·网络·人工智能·科技·光模块
fengyehongWorld29 分钟前
Linux 安装frp实现内网穿透
linux·运维·服务器
一技安身2 小时前
【信创】银河麒麟V10服务器使用安装光盘Packages自建本地yum源
linux·运维·服务器
码农客栈2 小时前
Linux I2C驱动实验
linux·运维·驱动开发
爱喝水的鱼丶3 小时前
SAP-ABAP:隐式/显式增强开发规范与避坑指南:10 类典型错误与运维方案
运维·性能优化·sap·abap·增强·经验交流
企业解惑小助手4 小时前
如何禁止文字复制?企业文档防复制项目需求拆解方案
运维·数据库·安全
蓝速科技4 小时前
酒店门店 AI 数字人前台场景适配与落地指南
大数据·运维·数据结构·数据库·人工智能·科技
yyk333244 小时前
Linux常见的基础命令
linux·运维·服务器