将计算机名称和用户名传递到批处理脚本中
我正在将文件从一个文件夹复制到另一个文件夹中。我想以这种特定方式命名目标文件:
filename-currentdatetime-computername-username.txt
How do I do this using a Batch file with Windows Commands?
我需要获取原始文件名,后跟当前系统日期时间,然后是计算机名称和登录的用户
I am copying a file from one folder into another folder. I would like to name the destination file in this specific way:
filename-currentdatetime-computername-username.txt
How do I do this using a batch file with Windows commands?
I need to get the original filename followed by the current system date time and then the computernaem and the user that is logged on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不关心确切的日期格式,此命令将复制文件并在目标文件名中包含日期、时间、用户和计算机名称。
日期和时间将采用操作系统的默认日期格式。请注意,某些日期格式可能包含文件名中不允许的字符。
为了使命令可移植,您需要自己指定格式。以下示例说明了如何创建文件名中有效的格式日期: 在 Windows 批处理脚本中格式化日期和时间
If you don't care about the exact date format, this command will copy a file and include the date, time, user and machine name in the target file name.
The date and time will be in the default date format of your OS. Beware that some date formats can contain characters which are not allowed in file names.
To make the command portable you need to specify the format yourself. Here are exampled of how to create format dates that are valid in file names: Format date and time in a Windows batch script
%time%
是时间变量%computername%
是计算机名称的变量%username%
是用户名变量。您应该能够使用它们来获取命名文件所需的所有数据。
%time%
is the variable for time%computername%
is the variable for the computer name%username%
is the variable for user name.You should be able to use those to get all of the data you need to name the file.