批处理:复制文件形式源到目的地 - 找不到文件指定的错误
我有一个文件夹结构,其中每个文件夹有一个我想复制到新目标的excel文件。批处理:复制文件形式源到目的地 - 找不到文件指定的错误
示例:
源路径:C:\ Data \ 0。 MyFolder文件\ 1。模板\ 00。文件夹0 \ File.xlsb
目标路径:C:\ Data \ 0。 MyFolder文件\ NewFolder \ 00。文件夹0 \ File.xlsb
“00.文件夹0”是存储在数组中的名称。所以我使用for循环来创建基于数组中名称的新目录,并创建新的类似结构。
我收到消息“系统找不到指定的文件。”试图将一个文件从一个文件夹复制到另一个文件夹时。
当我打印文件的路径似乎是正确的。我究竟做错了什么?
下面是代码:
@echo off
@break off
@title Generate Subfolders
@color 0a
@cls
setlocal EnableDelayedExpansion
SET "batch_path=%~dp0"
SET "first_folder=01. Folder1"
SET "second_folder=02. Folder2"
SET "third_folder=03. Folder3"
:: Create the new Working Data folder
SET /p new_folder_name= Enter Directory Name:
SET "full_path=%batch_path%%new_folder_name%"
ECHO Working...
IF NOT EXIST ("%full_path%") (
MKDIR %new_folder_name%
IF "!errorlevel!" EQU "0" (
ECHO Folder created successfully.
) ELSE (
ECHO Error while creating folder.
)
) ELSE (
ECHO Folder already exists.
)
SET "folders_list="%first_folder%" "%second_folder%" "%third_folder%""
SET "templates_folder=C:\Data\0. MyFolder\1. Templates"
FOR %%f in (%folders_list%) DO (
SET "updated_full_path=%full_path%\%%f"
SET "template_full_path_file=!templates_folder!\%%~f\file.xlsb"
:: Displays the path file correctly
ECHO !template_full_path_file!
MKDIR "!updated_full_path!"
:: However I cannot copy the file to new destination
COPY template_full_path_file updated_full_path
PAUSE
)
PAUSE
EXIT
您还没有copy
命令解决路径。
COPY "!template_full_path_file!" "!updated_full_path!"
非常感谢你! @LotPings建议我也加双引号。 –
漂亮!更新了答案。 – sohaib
随后处理引号。 '%% f'包含引用了字符串的字符串,它应该是'SET'updated_full_path =%full_path%\ %%〜f“',并且@SAhmad已经指出'!'丢失了,但是由于pathes包含空格也可以引用:'COPY“!template_full_path_file!” “!updated_full_path!”' – LotPings
@LotPings非常感谢! :) –