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.

masoud
  • 55,379
  • 16
  • 141
  • 208
  • 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. – Mofi Jun 17 '15 at 06:10
  • yes it is in for loop i replaced variable with /creationYear and echo with !creationYear! still not working – Saurabh Kalyankar Jun 17 '15 at 06: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__. – Mofi Jun 17 '15 at 06:14
  • Possible duplicate of [Windows Batch help in setting a variable from command output](http://stackoverflow.com/questions/1746475/windows-batch-help-in-setting-a-variable-from-command-output) and [Example of delayed expansion in batch file](http://stackoverflow.com/questions/10558316/example-of-delayed-expansion-in-batch-file). – Mofi Jun 19 '15 at 16:57

1 Answers1

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

npocmaka
  • 55,367
  • 18
  • 148
  • 187