Batch file 批处理文件以生成文件

Batch file 批处理文件以生成文件,batch-file,Batch File,好的,我正在尝试创建一个批处理文件来生成一系列文件和文件夹,但找不到如何执行该操作 我的想法是: FOR /f "Tokens=* delims=" %%I IN (export2.csv) DO call:create %%I GOTO:EOF :create ECHO 1 >>%~pd0%1 但它根本不起作用。因为我不知道您的数据文件看起来如何,所以很难在这里给出好的建议,但您的代码可以稍微清理一下: set "filepath=%~dp0" for /f "tokens=*

好的,我正在尝试创建一个批处理文件来生成一系列文件和文件夹,但找不到如何执行该操作

我的想法是:

FOR /f "Tokens=* delims=" %%I IN (export2.csv) DO call:create %%I GOTO:EOF

:create ECHO 1 >>%~pd0%1

但它根本不起作用。

因为我不知道您的数据文件看起来如何,所以很难在这里给出好的建议,但您的代码可以稍微清理一下:

set "filepath=%~dp0"
for /f "tokens=* delims=" %%I in (export2.csv) do call :create "%%I"
rem This is needed to avoid stepping into the subroutine again
goto :eof

:create
rem This will create an empty file instead of one that contains a single line with 1
copy nul "%filepath%%~1"
goto :eof

不过,这不会创建任何目录。你可以用
md

创建那些,我在不久前就发现了这一点,下面是我的结论。它将生成路径并创建一个空文件,文件名列在masterlist.csv中

源代码

@ECHO OFF
CHDIR "%~dp0"
SET Count=0
ECHO/ Generating Necessary File, please Wait...
FOR /F %%A IN (Masterlist.csv) DO CALL:MKDIR %%A
EXIT /B

:MKDIR
SET /A Count+=1
SET "Path=%~dp1"
SET "File=%~nx1"
IF NOT EXIST "%Path%" MKDIR "%Path%
IF NOT EXIST "%Path%" CALL:ERROR "Path"
IF NOT EXIST "%Path%\%File%" ECHO/ >>"%Path%\%File%"
IF NOT EXIST "%Path%\%File%" CALL:ERROR
EXIT /B

:ERROR
IF NOT EXIST "Errorlog.csv" ECHO Error, Line Count>>Errorlog.csv
ECHO %~1, Line %Count%>>Errorlog.csv
Masterlist.csv中的一些示例行

2006\MS06-003\Office2000\office2000-kb892842-fullfile-enu.exe
2006\MS06-003\Office2003\office2003-kb892843-fullfile-enu.exe
2006\MS06-003\Office2003\WinSec-MS06-003-009-P44333-outlook2003-kb892843-fullfile-enu.exe
2006\MS06-003\OfficeXP\officexp-kb892841-fullfile-enu.exe
2006\MS06-006\WindowsMedia-KB911564-x86-ENU.exe
2006\MS06-007\2003\WindowsServer2003-KB913446-x86-ENU.exe
2006\MS06-007\XP\WindowsXP-KB913446-x86-ENU.exe
2006\MS06-012\2003\office2003-KB905756-FullFile-ENU.exe
2006\MS06-015\2000\Windows2000-KB908531-x86-ENU.EXE
2006\MS06-015\2003\WindowsServer2003-KB908531-x86-ENU.exe

是的,我这样做的问题是它没有创建我所需要的目录。
mkdir
/
md
可以创建一个完整的目录树,如果它还不存在的话。这应该很容易集成。在第二行输入错误。应该是
%~dp0%1