【发布时间】:2020-02-19 22:03:12
【问题描述】:
我的作业如下:
1. Create a batch file that does the following:
- Accepts from the command line the following variables:
- Year (four digit number) of log files that they want to archive
- Month (two-digit number) of log files that they want to archive
- Does not display any of the commands to the screen
- Display just the files names of all of the files in the directory and subdirectories that have the archive attribute turned on in a “wide” display on the screen.
- Display the message “Beginning archive utility at” and then display the current date and time.
- Create a subdirectory called archive. If this directory already exists, do not report out an error message.
- If there are files that correspond to the month and year:
- Create a subdirectory in the archive directory that corresponds to the month and year entered (six digit number using the format yyyymm)
- Move all files with a file name that begins with the corresponding month and year entered (six digit number using the format yyyymm)
- If there are not any files that correspond to the month and year entered
- Returns an error message to explain what happened and the type of input that was expected
- Turn off the archive attribute of only the files that have been moved.
- Display just the files names of all of the files in the directory and subdirectories that have the archive attribute turned off.
我不完全理解这是什么意思,我已经在谷歌上寻求帮助,但他将我指向资源 https://ss64.com/nt/syntax-args.html。我也为此尝试过堆栈溢出文章,但我不明白如何接受“来自命令行的变量”我必须做一个 set /p %% 吗?但是我如何通过它来搜索文件夹中包含这些日志文件的文件?
【问题讨论】:
-
没有看到整个问题/任务,我们的解决方案可能不相关。你应该从命令提示符运行一个批处理文件,向它发送两个参数
YYYY和MM还是你的批处理文件应该询问最终用户输入这两个参数中的每一个,然后使用输入了什么。 (从您指向的页面来看,我假设是前者。)另外,某种指示您正在搜索的文件名的确切外观以及对我们有帮助的地方。跨度> -
批处理文件会询问最终用户的每个参数,然后使用输入的内容来搜索一个文件夹,其中包含不同日期的日志文件。它还说不应在屏幕上显示任何命令行,我认为这意味着@echo off。我可以将整个内容添加到帖子中
标签: windows batch-file command-line