c#判断是文件还是文件夹,如果是文件,获取文件名并获取相同字符之间的值

c语言 遍历文件夹中所有文件名,C# 遍历文件夹下所有子文件夹中的文件,得到文件名... 假设a文件夹在F盘下,代码如下。将文件名输出到一个ListBox中using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication1{public partial... 阅读详情

首先判断是不是文件夹:
以 以下路径为例

E:\TIF\06-T2.33101\06-T2.33101-00001\06-T2.33101-00001-001\001.TIF

string lj1=“E:\TIF\06-T2.33101\06-T2.33101-00001\06-T2.33101-00001-001\001.TIF”;
string lj2=“E:\TIF\06-T2.33101\06-T2.33101-00001”;
string lj3=“06-T2.33101-00001-001”;

            //如果是文件夹 ,就会返回false  
            if (File.Exists(lj2) == false)
            {
                Fcfht(lj2);//递归
            }
            
            //如果是文件 ,就会返回true
            if (File.Exists(lj1) == false)
            {
                Fcfht(lj1);//递归
            }
            else
            {
                    //获取  001  
                    string str = Path.GetFileNameWithoutExtension(lj1);
			        //获取   06-T2.33101-00001
                    string str1 = lj3.Substring(0, lj3.LastIndexOf("-"));
                    //获取   06-T2.33101
                    string str0 = str1.Substring(0, str1.LastIndexOf("-"));
                    //获取T2.33101
					string str33 = str0.Substring(str0.LastIndexOf("-") + 1);
					
                    //不足5位补0   00001
                    string str00 = str.PadLeft(5, '0');

		            int i = 1;
                    // 不足3位补0    001 
                    string i0 = i.ToString().PadLeft(3, '0');
                    
					// 判断 dahname 文件是否为0字节
                   FileInfo file = new FileInfo(lj1);
                   long size = 0;
                   size = file.Length;//文件大小。byte
                   if(size == 0 ){}
                   else{}
            }
Unity中获取特定文件夹下文件名包含特定字符串的文件路径 平时在工作中有时可能会碰到想要获得自己项目文件夹下文件名中包含某个特定字符或字符串的文件及其路径,这时如果只是在Unity的Project栏中输入这个特定的字符串来查找的话,虽然可以找到这些文件,但要获取路径就只能手动打开每个文件所在的文件夹位置。作为一个程序员,这样做显然效率太低,不符合程序员的Geek风格,所以我想到利用Unity的Editor功能写一个小脚本来获取需要的文件路径,代码如下。 阅读详情

相关推荐

C#中读取文件夹和文件时,根据文件夹或者文件名调整读取的顺序

当读取文件夹或者文件时,有时会遇到这样一个问题,文件夹或者文件的命名为1,2,3,4,5,6,7,8,9,10,11,12等,在电脑上面显示时,是按照递增的方式,可是当用C#来读取时,默认按照的顺序是1,10,11,12,2,20,21,3,4,5,6,7,8,9,如果对文件顺序要求很严格,这样明显不符合要求。那怎么对这样进行再次排序呢。

qiufenpeng的博客 8036

C#判断字符串代表的是文件还是文件夹

首先说明仅仅通过字符串来判断它是指文件还是文件夹,是不严谨的,无法完美的实现。有三种方法可以不完美或者有条件实现判断。 方法一:最简单的方法,判断给定的字符串有没有扩展名。有扩展名的就是文件,没有扩展名的就是目录。 string path=@"C:\windows"; if(System.IO.Path.HasExtension(path)){ MessageBox.Show("这是一个文件夹"); } else{ MessageBox.Show("这是一个文件"); } 问题显而易见,有些文件夹中

Bibiolatrist的博客 7017

C#实现将图片另存到新建的文件夹中

需求:        将目录fullPath下的图片.jpg文件分类存储到指定的文件夹中(指定的文件夹要求以图片中某个特殊字符串作为名字),例如fullPath目录下的图片文件名称如下:       0000098286-1-0-20150806181038-454(未知)()(无)--上行-机动车-001-full-1_WrongCL.jpg       0000098303-1-0-20

xuejiaodream的专栏 7772

C#中如何判断指定的路径是文件还是文件夹

string path = @"D:\aaa"; if (Directory.Exists(path)) { Console.WriteLine("文件夹"); } else { if (File.Exists(path)) { Console.WriteLine("文件"); } else { Console.WriteLine("无效路径"); } } Console.Read(); ...

qq_34573534的博客 5472

C#判断一个文件夹内是否存在子文件夹或文件

C#判断一个文件夹内是否存在子文件夹或文件

C#判断获取的是文件夹还是文件的实例

如下所示: if(File.Exists(path)){ // 是文件 }else if(Directory.Exists(path)){ // 是文件夹 }else{ // 都不是 } 以上这篇C#判断获取的是文件夹还是文件的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。 您可能感兴趣的文章:C#实现判断文件夹存在与否并创建文件夹的方法C#判断本地文件是否处于打开状态的方法C#判断指定文件是否是只读的方法C# 如何判断两个文件内容是否相同的方法

c#判断一个路径是否是文件夹

c#判断一个路径是否为文件夹

KingOfBadLuck的博客 979

Computers & Security 投稿实战:从零到一详解避坑指南

本文详细解析了向《Computers & Security》投稿的全流程避坑指南,包括ORCID账号注册、文件格式统一、Editorial Manager®系统操作技巧等关键步骤。特别强调了cover letter撰写、Declaration of Interest Statement准备以及PDF生成后的检查要点,帮助研究者高效完成投稿流程。

weixin_29228203的博客 676

如何用C#获取指定文件夹下所有文件名?

如题:         比如我要在ASP.NET程序的服务器上DATA文件夹下所以有文件名.然后输出.希望用C#代码实现... 可以用   Directory.GetFiles();方法... 返回包含文件名的路径.然后再截取文件名 如: string[]   filenames=Directory.GetFiles(path); for(string   files   in   filen

apinghappy 1万+

ARM 汇编指令:LSL(逻辑左移) 和 LSR(逻辑右移)

ARM 汇编中的 LSL(逻辑左移)和 LSR(逻辑右移)是基础移位指令,分别实现二进制位的左移和右移操作。LSL 低位补0,等效于乘以2^n;LSR 高位补0,等效于无符号除以2^n。这两个指令可以单独使用或与其他指令结合(如ADD、MOV等),利用ARM的"桶形移位器"硬件实现高效运算。关键特性包括:移位范围0-31(LSL)或1-32(LSR),可选更新标志位,以及与其他指令结合时的无额外开销优势。LSR与ASR(算术右移)的主要区别在于高位填充方式,分别适用于无符号和有符号数处理

guigenyi的专栏 1817

bartender 10.1破解版|bartender条码打印10.1

点击下载出处:BarTender10.1破解版 bartender10.1破解版是一款专业的条码打印软件,在行业内广受好评,通过使用bartender我们可以将标签设计这个复杂的过程变得更简便,在设计中快速调整,即刻打印,非常迅速,BarTender10.1破解版不仅支持的标签类型包括EPC Class 1 、Gen2 、ISO 18000-6b 、ISO 15693 、Tag-It 、I-CO...

weixin_44924147的博客 6万+

C#创建文件夹

方法一: c#创建目录和文件夹,数据写入并生成txt文件 c#创建目录: // 获取程序的基目录。 System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径。 System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName // 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。 System.Environment.CurrentDirectory // 获取应用程序的当

caixiaobai2019的博客 6587

VS2022下C# WPF项目一键打包成独立exe的完整指南

本文提供了一份在Visual Studio 2022中将C# WPF项目一键打包成独立可执行exe文件的完整指南。通过配置项目属性、启用单文件发布和自包含模式,开发者无需依赖第三方工具,即可生成可在未安装.NET运行时的电脑上直接运行的独立程序,极大简化了桌面应用的分发流程。

weixin_28831399的博客 674

C#获取FTP目录下文件夹、文件的方法,进而判断FTP下指定文件夹是否存在

直接说方法: 1 public string[] GetFileList() 2 { 3 string[] downloadFiles; 4 StringBuilder result = new StringBuilder(); 5 FtpWebRequest reqFTP; 6 ...

Sayesan的专栏 5688

SAP ABAP干货:用REUSE_ALV_GRID_DISPLAY_LVC实现ALV多屏幕独立布局(含handle参数详解)

本文详细解析了SAP ABAP中如何使用REUSE_ALV_GRID_DISPLAY_LVC函数实现ALV多屏幕独立布局,重点介绍了handle参数的技术原理和实际应用。通过变式标识符和LTDX表存储机制,开发者可以确保不同ALV报表屏幕的布局设置互不干扰,提升复杂报表场景下的用户体验。

weixin_29268267的博客 312

大模型之Spring AI实战系列(二):Spring Boot + OpenAI 打造聊天应用全攻略

本篇文章是《Spring AI实战》专栏的第一篇开发入门文章,我们将借助一个完整的OpenAI聊天应用示例,详细介绍如何运用Spring Boot和Spring AI快速搭建一个支持OpenAI API的聊天服务,全面涵盖基础对话、流式对话、多提供商配置等核心功能。

寻道AI,探索AI无限可能! 6872

C#获取文件夹中所有文件的文件名

C#获取文件夹中所有文件的文件名 想实现这样一个功能:批量修改一个目录所有jpg文件的文件名,在其原始基础上加上特定字符串我先把一个目录里所有的格式为jpg的文件名存储到数组里,然后统一修改数组值来批量修改jpg文件的文件名 using System;us...

baihuomeng2210的博客 1499

File Load Error for Untitled.ipynb Unhandled error 解决方案

本文主要介绍了File Load Error for Untitled.ipynb Unhandled error 解决方案,希望能对使用jupyter notebook的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

C#去掉文件夹或文件名非法字符

今天实现有输入字符串创建文件夹的功能,需要检查字符串中是否包含不能在文件夹中使用的非法字符。//string strFileName = "文件名称";/// C#快速剔除字符串中不合法的文件名。

网络Online 5862

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【C#|正则表达式】获取文件(夹)路径中的文件名或末级文件夹名

获取文件(夹)路径中的文件名或末级文件夹名 下面的C#代码实现了使用正则表达式获取文件(夹)路径的最后一段内容的功能。当参数传入文件夹路径时,方法返回的是末级文件夹名称;当参数传入文件路径时,方法返回的是文件名。 涉及的正则表达式说明: [^/\\]:表示匹配除了斜杠(/)和反斜杠(\)以外的任意字符,双反斜杠用于转义 +:表示匹配前面的表达式一次或多次 [/\\]:表示匹配斜杠(/)或反斜杠...

Arvin的博客 5558

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

C# 批量修改文件名称

目录目的思路方法新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 目的 对文件夹中所有文件名实现批量修改(添加...

菩提有树的博客 3936

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

C# 中判断文件及文件夹是否存在

C# 中判断文件及文件夹是否存在   2011-05-19 17:37:06|  分类: asp.net学习 |  标签:学习   |举报|字号 订阅 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using S

zhaohongx的专栏 3883

C# 获取文件名及扩展名

string aFirstName = aFile.Substring(aFile.LastIndexOf("\\") + 1, (aFile.LastIndexOf(".") - aFile.LastIndexOf("\\") - 1));  //文件名 string aLastName = aFile.Substring(aFile.LastIndexOf(".") + 1, (aFile.

佚玥 8406
上一篇: 如何将 DotNetBar2控件加入到C#的winform工具箱中?
下一篇: 批处理命令,删除的文件路径有中文怎么办
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值