我正在制作一个脚本,该脚本将基于模板创建一个文件夹和子文件夹。我在预期的位置创建了文件,但它也会拆分桌面上的所有文件。
echo off
cls
echo Type The SO number, Customer, and Job named when asked. Then press Enter
echo.
set /p SO="SO #: "
set /p Customer="Customer Name: "
set /p JOB="Job Name: "
set folder="%SO%"_"%Customer%"_"%JOB%"
echo %folder%
set dir="F:\Sales\User 1\_QUOTES"
set final="%dir%\%folder%"
set dst="%final%/1 - Estimating Original Quote Material"
if not exist %final% (
mkdir "%dst%"
copy /-Y "%dir%\_takeoff.xlsx" %dst%
mkdir "%dst%\Downloads"
mkdir "%dst%\Plans"
mkdir "%dst%\Quotes"
mkdir "%dst%\Cut Sheets"
mkdir "%dst%\Venders"
mkdir "%final%\2 - Signed Quote - Contract\Non-Current Purchase Orders"
mkdir "%final%\3 - Special Purchase Trading Goods"
mkdir "%final%\4 - Engineering\2 - Submittals"
mkdir "%final%\4 - Engineering\3 - Approvals"
mkdir "%final%\4 - Engineering\4 - Drawings in Progress\Released Production Drawings"
mkdir "%final%\5 - Final Production Drawings"
mkdir "%final%\6 - Q.C. Document"
mkdir "%final%\7 - Project Management _ Schedule"
)
pause
答案 0 :(得分:0)
修复并精简了一些内容:
@echo off
echo Type The SO number, Customer, and Job named when asked. Then press Enter.
echo.
set /p "SO=SO #: "
set /p "Customer=Customer Name: "
set /p "JOB=Job Name: "
set "folder=%SO%_%Customer%_%JOB%"
echo %folder%
set "dir=F:\Sales\User 1\_QUOTES"
set "final=%dir%\%folder%"
set "dst=%final%\1 - Estimating Original Quote Material"
if not exist "%final%" (
md "%dst%" "%dst%\Downloads" "%dst%\Plans" "%dst%\Quotes" "%dst%\Cut Sheets" "%dst%\Venders" "%final%\2 - Signed Quote - Contract\Non-Current Purchase Orders" "%final%\3 - Special Purchase Trading Goods" "%final%\4 - Engineering\2 - Submittals" "%final%\4 - Engineering\3 - Approvals" "%final%\4 - Engineering\4 - Drawings in Progress\Released Production Drawings" "%final%\5 - Final Production Drawings" "%final%\6 - Q.C. Document" "%final%\7 - Project Management _ Schedule"
copy /-Y "%dir%\_takeoff.xlsx" "%dst%"
)
pause
cls
,除非从其他地方调用了该批处理。set
变量的开头。copy /-Y "%dir%\_takeoff.xlsx" %est%
固定为%dst%
,因为未设置%est%
,因此很可能会将.xlsx
文件复制到当前目录中(我猜您正在运行从您的桌面批处理)。mkdir
东西放在一行上并使用md
(做同样的事情)就个人而言,如果我要创建多个文件夹,则可能会将每个大路径设置为任何其他命令之前的变量,或者将每一行添加到文本文件中,如下所示:
1-估计原始报价材料\下载
1-估算原始报价物料\计划
1-估算原始报价材料\报价
1-估计原始报价材料\切割纸
1-估算原始报价材料\供应商
2-签名报价-合同\非当前采购订单
3-特殊购买贸易商品
4-工程\ 2-提交
4-工程\ 3-批准
4-工程\ 4-进行中的工程图\已发布的生产工程图
5-最终生产图纸
6-Q.C.文件
7-项目管理_进度表
,然后循环遍历,为每个文件夹创建一个文件夹;这将大大清除您的代码块,并且如果您想进行一些调整,则只需在文本文件中添加/删除/修改行即可。它将使该块看起来像这样:
@echo off
echo Type The SO number, Customer, and Job named when asked - then press Enter.
echo.
set /p "so=SO #: "
set /p "cus=Customer Name: "
set /p "job=Job Name: "
set "fld=%so%_%cus%_%job%"
echo %fld%
set "dir=F:\Sales\User 1\_QUOTES"
set "fin=%dir%\%fld%"
if not exist "%fin%" (
for /f "usebackq tokens=*" %%A in ("%txt%") do (
md "%fin%\%%A"
)
copy /-Y "%dir%\_takeoff.xlsx" "%fin%\1 - Estimating Original Quote Material\%cus%_takeoff.xlsx"
)
pause
答案 1 :(得分:0)
作为给出答案的补充,如果您更易于阅读和维护,也可以通过for-loop,(以您的错字为Venders
,用{ {1}}):
Vendors
再一次告诉您,您确实需要对用户输入进行验证和确认,然后再盲目地尝试使用这三个变量来创建和传播所有这些目录!