Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file .bat生成包含删除的文件名的txt文件_Batch File - Fatal编程技术网

Batch file .bat生成包含删除的文件名的txt文件

Batch file .bat生成包含删除的文件名的txt文件,batch-file,Batch File,我想通过将一堆文件放到.bat文件中来生成.abook文件。所述文件应命名为已删除文件的文件夹名 1. ###已删除文件的文件夹名称位于此处### ###这里是第一个filename.extension### ###第二个filename.extension在这里### 编辑: 这就是我现在拥有的。它正在做我想做的事情,但我一直在想如何让它处理多个文件 @ECHO关闭 对于(.)中的%%*请设置CurrDirName=%%~nx* echo^>%CurrDirName%.a确定 echo^>

我想通过将一堆文件放到
.bat
文件中来生成
.abook
文件。所述文件应命名为已删除文件的文件夹名


1.
###已删除文件的文件夹名称位于此处###
###这里是第一个filename.extension###
###第二个filename.extension在这里###
编辑: 这就是我现在拥有的。它正在做我想做的事情,但我一直在想如何让它处理多个文件

@ECHO关闭
对于(.)中的%%*请设置CurrDirName=%%~nx*
echo^>%CurrDirName%.a确定
echo^>>%CurrDirName%.abook
echo^>>%CurrDirName%.abook
回显^1^>>%CurrDirName%.a确定
echo^%CurrDirName%^>>%CurrDirName%.aOK
echo^>>%CurrDirName%.abook
echo^>>%CurrDirName%.abook
对于%%G IN(%*)DO(
echo^%~nx1^>%CurrDirName%.abook
)
这是我拖放两个文件(file1、file2)时输出的folderName.abook文件


1.
发展
file1.txt
file1.txt
如何使它输出所有文件而不仅仅是第一个文件并重复这些文件


谢谢

在批处理文件上拖动多个文件时,您会得到一个以空格分隔的文件列表。试试这个测试

@echo %*
@pause
确定集合中删除的文件的文件夹名称。像这样的

for %%* in %* do set CurrDirName=%%~nx*
echo %CurrDirName%
回显文件的第一部分

@echo off
echo ^<?xml version="1.0"?^>^<Audiobook^>^<Header^> ... </FileList>

如果您是编程新手,请帮自己一个忙,不要从Windows批处理开始。它是一种糟糕的编程语言,现在已经基本过时了。请看一看例如Python或者如果您出于某种原因需要使用Windows Powershell附带的任何东西。这不是免费的代码编写服务!请至少阅读全文,了解本网站的工作原理!多亏了你,我才开始了,但我一直在努力寻找循环。你能给我指出正确的方向吗?我看不懂太妃糖。到目前为止,它的成功程度如何?写一点,跑一点。重复它。Google“For loop in batch files”发现了这一点,但我的问题是%%nx*不起作用,只有%%nx1起作用。@TõnuRäk,问题是@Paul使用
%*
作为
变量引用的
,因此
%~nx*
与此相关,它与命令行参数
%*
无关。。。我强烈建议对变量引用使用不同的
,以避免这种混淆……更新了我的答案@TõnuRäk
FOR %%G IN (%*) DO (
echo    ^<File^>%%G^</File^>>>%CurrDirName%.abook
)
FOR %%G IN (%*) DO (
echo    ^<File^>%%~xG^</File^>>>%CurrDirName%.abook
)
Variable with modifier  Description

%~G                     Expands %G which removes any surrounding 
                        quotation marks ("").
%~fG                    Expands %G to a fully qualified path name.
%~dG                    Expands %G to a drive letter only.
%~pG                    Expands %G to a path only.
%~nG                    Expands %G to a file name only.
%~xG                    Expands %G to a file extension only.
%~sG                    Expands path to contain short names only.
%~aG                    Expands %G to the file attributes of file.
%~tG                    Expands %G to the date and time of file.
%~zG                    Expands %G to the size of file.
%~$PATH:G               Searches the directories listed in the PATH environment 
                        variable and expands %G to the fully qualified name of 
                        the first one found. If the environment variable name is 
                        not defined or the file is not found by the search,
                        this modifier expands to the empty string.