Windows 10: Using variables with the rename command in a batch file

Discus and support Using variables with the rename command in a batch file in Windows 10 Network and Sharing to solve the problem; Hello, I am trying to use variables in renaming a robocopy log file but I continually receive a 'syntax error'. Everything works perfectly until I... Discussion in 'Windows 10 Network and Sharing' started by pww2, Mar 6, 2020.

  1. pww2 Win User

    Using variables with the rename command in a batch file


    Hello,

    I am trying to use variables in renaming a robocopy log file but I continually receive a 'syntax error'. Everything works perfectly until I use the rename command. I am using the latest build of Windows 10. Any advice will be appreciated, thank you. The batch file script is as follows:


    @echo off

    REM set date stamp

    for /f "delims=" %%a in 'wmic OS Get localdatetime ^ find "."' do set dt=%%a

    set YY=%dt:~0,2%

    set MM=%dt:~4,2%

    set DD=%dt:~6,2%

    set stamp=%YY%%MM%%DD%


    REM set variables

    set fname=placeHolder

    set source="C:\Me\SrcPath\%fname%"

    set target="C:\Me\tgtPath\%fname%"

    set project=ListMake

    set tempLog="C:\Me\LogFiles\temp.log"

    set finalLog="C:\Me\LogFiles\log%project%Backup%stamp%.log"


    Rem use robocopy to to copy src folders to tgt folder and log data in temp log


    Rem copy src1 folder

    set fname=src1

    Robocopy %source% %target% /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32 /V /NP /LOG+:%tempLog%


    REM Copy src2 folder

    set fname=src2

    Robocopy %source% %target% /MIR /XA:SH /XD AppData /XJD /R:5 /W:15 /MT:32 /V /NP /LOG+:%tempLog%


    REM************The rename below is where I continuously get an error.

    REM************I have tried setting variable values with and without quotes

    REM************as well as trying the rename command with and without quotes around the variables

    REM************no matter which permutation I use the batch file returns a syntax error during rename


    ren %tempLog% %finalLog% /q



    Pause

    :)
     
    pww2, Mar 6, 2020
    #1

  2. How to Batch Rename files ?

    I have a lot of files I want to give names to. I already found a way to get names into a text I need. So all these names i have in text, I want to give to other files.

    How do i do this in a batch process ?

    Currently trying to learn FastStone Image viewer. Seems to be updated version of Resizer by the same company?
    That has been useful for other batch processes for images . But I've yet to figure the batch naming options .

    A different software I'm considering for this task is called Advanced Renamer .

    Maybe I've become too slow through the years because :
    I've been looking for the right tutorial that I can clearly understand and found none .
    They seem to be out of my grasp .


    Note : I currently use a bat file, that takes the names of other files I have in a folder and puts them into a text file.

    ( I'd prefer a one click Bat process ideally for this specific task ) .

    So I'd be happy with a bat file that can also take those names in my text list
    and apply them to files I want to rename in any given folder with those . If anyone knew how to do that.

    It don't matter the order applied - as long as each file in the folder receives one name from the list.
    The names I pulled are from images in a folder. The names are to be applied to a equal number of files ,
    which is a different extension. so no worry about them having the same name. So just the names .




    - - - Updated - - -

    I found this thread. But unsure how to apply it and its replies into the bat i need ?

    stackoverflow rename-files-after-a-list-of-names




    Update possible reference
    for loop - Creating a batch file to rename TXT files based on content (removing inappropriate syntax) - Stack Overflow

    - - - Updated - - -

    and yet another reference i need help understanding if its useful
    windows - Generate file-folder list.txt file in a directory/subdirectory & rename list.txt to folder/subfolder name using dir & ren command in a batch file - Stack Overflow
     
    OtherWay1982, Mar 6, 2020
    #2
  3. FordGT90Concept, Mar 6, 2020
    #3
  4. Using variables with the rename command in a batch file

    How to Batch Rename files ?

    First, make a backup of the files. Bulk renaming can cause major problems so you will appreciate the backup if things go horribly wrong.

    Second, as you mentioned, there are programs to handle renaming for you. Check out: Introduction - Bulk Rename Utility

    Third, if you want to use a batch file (and you've completed step 1), try this from the command prompt:

    for /f "delims=" %v in (TextFileWithFilenamesToRename) do echo ren "%v" "%v_NewFilename"

    The previous command will show you the how the ren command will work without actually changing the filenames.
    Without knowing what the text file with the name of the files to rename looks like, you may have to tinker
    with the command to get it right.

    If everything looks good, you can perform the actual rename command by removing the echo command as in:
    for /f "delims=" %v in (TextFileWithFilenamesToRename) do ren "%v" "%v_NewFilename"

    Good luck
     
    mahoneycutt, Mar 6, 2020
    #4
Thema:

Using variables with the rename command in a batch file

Loading...
  1. Using variables with the rename command in a batch file - Similar Threads - Using variables rename

  2. renaming multiple files using the command prompt

    in Windows 10 Gaming
    renaming multiple files using the command prompt: Hello,I had a few dozen files that used a naming convention beginning with an abbreviation for a city in this case, WI and then an alpha-numeric sequence that was unique to each file. I wanted to rename the files to include the entire city name in this case, Windsor without...
  3. Batch File Command???

    in Windows 10 Gaming
    Batch File Command???: I want to run a batch file that starts a backup program, but does not execute the next command until that program completes? How do I do this? https://answers.microsoft.com/en-us/windows/forum/all/batch-file-command/3af2ce6b-ace3-43cb-b6fb-5cbff8998736
  4. Batch File Command???

    in Windows 10 Software and Apps
    Batch File Command???: I want to run a batch file that starts a backup program, but does not execute the next command until that program completes? How do I do this? https://answers.microsoft.com/en-us/windows/forum/all/batch-file-command/3af2ce6b-ace3-43cb-b6fb-5cbff8998736
  5. batch rename files

    in Windows 10 Support
    batch rename files: hello, id like to remove characters in file names... using cmd, ive been able to remove "." (the dot) and replace it with a space and but hopefully keep the extention id like bou.bou.bou.txt to be renamed to bou bou bou.txt i tried : ren *.*.??? * *.??? obviously i want to...
  6. Rename files in batch.

    in Windows 10 Network and Sharing
    Rename files in batch.: Hi All.. I am having some files nearly 2000 in nos. in a particular folder. I just need to replace some portion. Is it possible that I can do it instantaneously.. if so please guide....Details are furnished below.Old file Name : P12478-12-71-41-1781-01.dwg...
  7. Is there a way to batch rename files?

    in Windows 10 Ask Insider
    Is there a way to batch rename files?: I have a file with pictures formatted as "A-B-C" and need to change all the dashes to underscore such as "A_B_C". Is there a way to do this as a batch in the folder somehow? submitted by /u/gingernuts13 [link] [comments]...
  8. Batch variables are not output?

    in Windows 10 Network and Sharing
    Batch variables are not output?: Hello everybody I have written the following script: @echo off setlocal enableDelayedExpansion :set/p again Z=Number of rows: set/p S=Number of columns: set/a Ze=%Z%+0 set/a Sp=%S%+0 if not %Z%==%Ze% ( cls echo error.. goto again) if %Z%==0 ( echo error... goto again )...
  9. How to Batch Rename files ?

    in Windows 10 Software and Apps
    How to Batch Rename files ?: I have a lot of files i want to give names to. I already found a way to get names into a text I need. So all these names i have in text, i want to give to other files. How do i do this in a batch process ? Currently trying to learn FastStone Image viewer. Seems to be...
  10. Batch Rename Deletes Files

    in Windows 10 Performance & Maintenance
    Batch Rename Deletes Files: Hey all, I just upgraded to Windows 10 last night, and I've been playing around with the new File Explorer. One thing I tried was the batch rename function (by which I mean just selecting multiple files and clicking "rename"). I quickly realized that it behaves differently...

Users found this page by searching for:

  1. batch ren mit variablen

    ,
  2. using variables in command prompt for renaming the files

    ,
  3. using variables in a windows file name