简体   繁体   English

在每周自动FTP下载中更改文件名

[英]Changing File Name in Auto Weekly FTP Download

I have a SCR file with the below commands 我有以下命令的SCR文件

open myftp.myserver.com
myusername
mypassword
lcd "c:\myfolder"
cd webfolder
get myfile09202012

I run this script with a BAT file as a Windows Task once per week. 我每周一次将带有BAT文件的脚本作为Windows任务运行。 This week, the file name to download is "myfile09202012". 本周要下载的文件名为“ myfile09202012”。 Next week, the file name would be "myfile09272012". 下周,文件名将为“ myfile09272012”。 How would I create a script to auto-generate the new file name every week? 我将如何创建一个脚本以每周自动生成新文件名?

pipe the output of this batch file to your script file, then run the resulting script in the normal way. 将此批处理文件的输出通过管道传输到脚本文件,然后以常规方式运行生成的脚本。

@echo off
echo open myftp.myserver.com
echo myusername
echo mypassword
echo lcd "c:\myfolder"
echo cd webfolder
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do echo get myfile%%a%%b%%c

it will use the current date to generate the filename 它将使用当前日期生成文件名

to incorporate the whole batch within another batch file, it would end up something like this: 要将整个批处理合并到另一个批处理文件中,结果将如下所示:

@ECHO OFF
cd c:\myfolder
echo open myftp.myserver.com > mySCRfile.SCR 
echo myusername >> mySCRfile.SCR 
echo mypassword >> mySCRfile.SCR 
echo lcd "c:\myfolder" >> mySCRfile.SCR 
echo cd webfolder >> mySCRfile.SCR 
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do echo get myfile%%a%%b%%c >> mySCRfile.SCR 
ftp -s:mySCRfile.SCR 

or 要么

@ECHO OFF
cd c:\myfolder
call MakeTheScr > mySCRfile.SCR 
ftp -s:mySCRfile.SCR 

I ended up using the following convention 我最终使用了以下约定

get myfile%date:~4,2%%date:~7,2%%date:~10%

If you type in the command 'echo %date%', you will receive today's date in the format 'Wed 10/10/2012' The string '%date:~4,2%' returns the above format at the 4th placeholder and returns the next 2 characters. 如果您输入命令'echo%date%',您将收到格式为'Wed 10/10/2012'的今天的日期。字符串'%date:〜4,2%'返回上述格式的第4个占位符,并且返回接下来的2个字符。

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

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