简体   繁体   English

Windows批处理上传后删除本地文件

[英]Windows Batch Delete Local file after upload

I have a windows batch script that cycles through all files in a folder and uploads to ftp and then deletes the local file. 我有一个Windows批处理脚本,该脚本可循环浏览文件夹中的所有文件,然后上传到ftp,然后删除本地文件。 This works great when there are no spaces in the file name: 当文件名中没有空格时,这非常有用:

@for %%f in (D:\local\file\path\nospaces\*.jpg) do (
  @echo cd  /remote/file/path/nospaces/ && @echo put %%f && @echo !del %%f
)>> %SCRIPT_NAME%

When spaces are introduced, I am able to get the file to upload by using quotes around the path, but the local will not delete: 引入空格后,我可以使用路径周围的引号来获取要上传的文件,但是本地不会删除:

@for %%f in ("D:\local directory with spaces\*.jpg") do (
  @echo cd "/remote directory with spaces/" && @echo put "%%f" && @echo !del "%%f"
)>> %SCRIPT_NAME%

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Thanks! 谢谢!

@for %%f in ("D:\local directory with spaces\*.jpg") do (
  @echo cd "/remote directory with spaces/" && @echo put "%%f" && @echo !echo "%%f">log.txt
)>> %SCRIPT_NAME%

ftp.exe -s:%SCRIPT_NAME%

for /f "delims=" %%f in (log.txt) do del /q "%%f"

del /q log.txt

This is where I ended up: 这是我结束的地方:

@for %%f in ("D:\\local directory with spaces*.jpg") do ( @echo cd "/remote directory with spaces/" && @echo put "%%f" && @echo %%f>>log.txt)>> %SCRIPT_NAME% @for %% f在(“ D:\\具有空格* .jpg的本地目录”)中执行(@echo cd“ /带空格的远程目录/” && @echo放入“ %% f” && @echo %% f >> log.txt)>>%SCRIPT_NAME%

@echo quit>> %SCRIPT_NAME% @echo退出>>%SCRIPT_NAME%

@REM = Now call FTP with our generated script @ftp -s:%SCRIPT_NAME% @REM =现在使用生成的脚本@ftp -s:%SCRIPT_NAME%调用FTP

@REM = Delete our temp script file and we are done @del %SCRIPT_NAME% /q @REM =删除我们的临时脚本文件,我们完成了@del%SCRIPT_NAME%/ q

for /f "delims=" %%f in (log.txt) do del /q "%%f" 为/ f“ delims =”(log.txt)中的%% f“执行del / q” %% f“

del /q log.txt 删除/ q log.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM