如何批量输出没有扩展名的文件名?

时间:2016-06-27 10:03:55

标签: batch-file

我是一个真正的“newbe”批处理并编写了以下脚本:

chdir C:\Users\oRookie\Desktop\batch
dir /b *txt > out.txt

文件out.txt已创建并包含out.txt

到目前为止,让我们努力获得更多优势。现在我希望它的内容只是out'。所以我需要一些方法来删除输出中的fileextension,但不删除fileextension本身。我该怎么办?

提前致谢。

3 个答案:

答案 0 :(得分:1)

尝试使用此代码并告诉我这是否正在寻找?

@echo off
Set Location=%userprofile%\Desktop\
Set Log=out.txt
if exist %Log% del %Log%
for /f %%i in ('dir /b /a-d %Location%*.txt') do @echo %%~ni >> %Log%
start "" %Log%

答案 1 :(得分:1)

不知道你为什么要这样做,但你可以从命令行做这样的事情:

type nul > out.txt | for /r %i in (*.txt) do @echo %~ni >> out.txt

脚本:

type nul > out.txt | for /r %%i in (*.txt) do @echo %%~ni >> out.txt

答案 2 :(得分:0)

这应该这样做:

if (!Environment.GetCommandLineArgs().Contains("/runAsOther"))
{
    var process = new Process();
    var securePassword = new SecureString();
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.FileName = "path to you application";
    process.StartInfo.Arguments = "/runAsOther";
    process.StartInfo.Domain = "domainname";
    process.StartInfo.UserName = "username";
    var password = "test";
    for (int x = 0; x < password.Length; x++)
        securePassword.AppendChar(password[x]);
    process.StartInfo.Password = securePassword;
    process.Start();
    Environment.Exit(1);
}

输出一个名为out.txt的txt,仅包含文本&#34; out&#34;