![]() ![]() Suppose you want your log file to be named using this date/time format: " Log_.txt". You can access different components of the date and time by slicing the internal environment variables %date% and %time%, as follows (again, the exact slicing values are dependent on the region configured in Windows): But this answer is about solving this issue using cmd.exe, not PowerShell, so we continue. One way it is more powerful is that it can deal with different Windows regions. Experiment and find what works best for your situation.īe aware that PowerShell is more powerful than cmd.exe. To mitigate this issue, surround your file name with quotes so that any unintended spaces in the file name won't break the command-line you're constructing. Also, with some regional settings, some components of the date or time may introduce a space into the constructed file name when their value is less than 10. Because of this, the exact values supplied in the examples below may not be correct for the region of Windows you use. Note: This technique takes the string output of internal Windows environment variables and slices them up based on character position. You can use the cmd.exe command processor to do this for you. To build upon answers by others here, it may be that you want to create an output file that has the date and/or time embedded in the name of the file. ![]() Use the cmd.exe command processor to build a timestamped file name to log your scheduled task's output ![]()
0 Comments
Leave a Reply. |