Windows 10: A batch file issue related to EnableDelayedExpansion

Discus and support A batch file issue related to EnableDelayedExpansion in Windows 10 Support to solve the problem; I had thought that I understood how "SETLOCAL EnableDelayedExpansion" works in a batch file in Win 10, but I'm running into something that I simply... Discussion in 'Windows 10 Support' started by hsehestedt, Dec 8, 2020.

  1. A batch file issue related to EnableDelayedExpansion


    I had thought that I understood how "SETLOCAL EnableDelayedExpansion" works in a batch file in Win 10, but I'm running into something that I simply cannot reconcile.

    Take a look at the code below:

    Code:
    Explanation: I'm simply setting a variable to a path. I want my path to end with a backslash (\) so I do a simple check to make sure that it does. I use an IF structure to check for this condition and to change the variable by adding a "" to the path if needed. If I display the variable to the screen AFTER I have already added the "", the displayed variable does not reflect that change while I am still in the IF structure.

    As soon as I exit the IF structure, the variable shows correctly.

    Here is sample output:

    Code:
    My understanding was that enabling delayed expansion in a batch file should correct this. Can anyone explain to me why it is not behaving that way?

    :)
     
    hsehestedt, Dec 8, 2020
    #1
Thema:

A batch file issue related to EnableDelayedExpansion

Loading...
  1. A batch file issue related to EnableDelayedExpansion - Similar Threads - batch file issue

  2. Batch File

    in Windows 10 Gaming
    Batch File: Hi, I am trying to create a batch file to determine whether a user account is signed on.I don't have enough experience to get it to @Echo it worked. Any advice please.Batch file:REM Query whether user SBackup is active@echo onsetlocal enabledelayedexpansionset...
  3. Batch File

    in Windows 10 Software and Apps
    Batch File: Hi, I am trying to create a batch file to determine whether a user account is signed on.I don't have enough experience to get it to @Echo it worked. Any advice please.Batch file:REM Query whether user SBackup is active@echo onsetlocal enabledelayedexpansionset...
  4. Batch Files

    in Windows 10 Gaming
    Batch Files: How do i make it that my batch file puts itself in to startup https://answers.microsoft.com/en-us/windows/forum/all/batch-files/6156404d-20d4-4f58-bee5-14629dbf7b10
  5. Batch Files

    in Windows 10 Software and Apps
    Batch Files: How do i make it that my batch file puts itself in to startup https://answers.microsoft.com/en-us/windows/forum/all/batch-files/6156404d-20d4-4f58-bee5-14629dbf7b10
  6. Batch Files

    in Windows 10 Network and Sharing
    Batch Files: How do i make it that my batch file puts itself in to startup https://answers.microsoft.com/en-us/windows/forum/all/batch-files/6156404d-20d4-4f58-bee5-14629dbf7b10
  7. Create batch files with Batch?

    in Windows 10 Software and Apps
    Create batch files with Batch?: How to create Batch and VBS files with Batch? So I write a batch file which I then convert to exe that creates new folders in a certain directory and then creates batch and VBS files with a certain content and saves them in the created folder. So it's similar to a program...
  8. Batch Files

    in Windows 10 Network and Sharing
    Batch Files: I want to make a batch file that will copy a specific folder from my USB stick to a folder on C:\ I want to know if it's possible to make a batch file that will take the folder from my USB drive no matter what the drive's letter is....
  9. Batch File

    in Windows 10 Support
    Batch File: I need a batch file to create a folder with sub folders. The sub folders will be named the current date, they will go in a folder on c drive. For example we can call the folder test and it would be in documents on c drive. Every time we run the batch file it would create a...
  10. DOS Command issued from Batch file

    in Windows 10 Network and Sharing
    DOS Command issued from Batch file: I have been running a batch file to list my personal file, and output the listing to a text file in a folder dv7. I then use the text file to compare to files on another computer or external drive, as backup. For some reason it no longer works. The command in the BAT file...