0

This part of script is not setting value for variable creationYear.

set creationYear=dir/T:C %%i | cut -c 7-10

echo %creationYear%

Showing ECHO is off, there is @ECHO OFF at start.

4
  • If this part of your batch code is inside a for loop or if condition, you need to use delayed environment variable expansion. Open a command prompt window, execute there set /? and read the help pages output now. On Stack Overflow search with [batch-file] delayed expansion and you will find thousands of questions and answers. Commented Jun 17, 2015 at 6:10
  • yes it is in for loop i replaced variable with /creationYear and echo with !creationYear! still not working Commented Jun 17, 2015 at 6:14
  • 2
    And you can't assign output of a command to an environment variable with the method you tried here. You need a for loop for this task. To get help on command for, open a command prompt window, execute there for /? and read the help pages output now. Of course on Stack Overflow there are thousands of questions and answers demonstrating how to assign output of a command to an environment variable using for. Commented Jun 17, 2015 at 6:14
  • Possible duplicate of Windows Batch help in setting a variable from command output and Example of delayed expansion in batch file. Commented Jun 19, 2015 at 16:57

1 Answer 1

0
for /f "tokens=* delims=" %%# in ('dir/T:C %%i ^| cut -c 7-10') do (
 set "creationYear=%%#" 
)
echo %creationYear%

despite you can get the creation date without external tools like cut

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.