我希望创建一个批处理文件,当给定一个路径时,它将计算其中的所有文件夹和子文件夹.到目前为止,我只能收集路径第一级内的文件夹数量.然后我将它传递给一个文本文件.
这是我到目前为止所拥有的:
for /f %%a in ('dir /b /ad %folder%^|find /c /v "" ') do set count=%%a
echo %count% folder(s^)>> !output!
Run Code Online (Sandbox Code Playgroud)
我接近得到我想要的东西吗?我需要做什么调整?
谢谢!
我正在通过C#中的Windows窗体选择带有文件夹路径的文本文件,并收集有关每个路径的信息.此时,我可以导入文件并仅显示文本文件中的第二个路径,但没有关于该文件夹的信息.这是我的代码:
private void btnFilePath_Click(object sender, EventArgs e)
{
//creating a stream and setting its value to null
Stream myStream = null;
//allowing the user select the file by searching for it
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = "c:\\";
open.Filter = "txt files (*.txt)|*.txt";
open.FilterIndex = 2;
open.RestoreDirectory = true;
//if statement to print the contents of the file to the text box
if (open.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = open.OpenFile()) != null)
{
using (myStream)
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用一个按钮来获取用户使用C#中的OpenFileDialog选择的目录的详细信息.目前我只能选择一个文件并获取该文件的完整路径.有没有办法让我可以在不必选择文件的情况下获取路径,甚至可以在路径末端修剪文件名?
我被困在一些非常简单的东西上,但似乎无法找到我正在寻找的东西.
我正在编写一个简单的应用程序来检查文件是否存在.它将被多个用户使用,因此不能包含特定的用户名.
我可以使用以下方式获取当前用户名
string userName = Environment.UserName;
Run Code Online (Sandbox Code Playgroud)
当我使用IF语句检查文件是否存在时,我收到文档"D"下的错误"无法识别的转义序列".
if (File.Exists(@"C:\Users\"+ userName +"\Documents\test.txt"))
{
lblUser.Text = "File exists";
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助指出我的愚蠢错误吗?
谢谢!