开发者

Passing a computer name and username into a batch script

I am copying a file from one folder into another folder. I would like to name the destination file in this specific way:

filename-curre开发者_运维知识库ntdatetime-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


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.

copy myFile.txt myFile-%date%_%time%-%computername%-%username%.txt

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% 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜