rename - renaming files to a new name folder using batch script -


have tried rename files in folder script, seems not work

@echo off setlocal enabledelayedexpansion set old=*.txt set new="c:\path file contains listed names"  /f "tokens=*" %%f in ('dir /b *.txt') (    set newname=%%f    set newname=!newname:%old%=%new%!    move "%%f" "!newname!"  ) 

what trying achieve script should pick set of listed names in file , rename each file in specified folder accordingly

first said want rename each file "accordingly" (accordingly what?), , later in comment said try rename files "with set of listed names in file". point cause several additional questions: have file 1 name in each line? must first file listed dir /b *.txt match first name listed in file, , on? other option? (why use move command "rename"?).

because objective not clear, can not said if code right or not. however, code does. suppose first file "firstfile.txt"; section:

set newname=%%f set newname=!newname:%old%=%new%! move "%%f" "!newname!"  

is executed way:

set newname=firstfile.txt set newname=!newname:*.txt="c:\path file contains listed names"! 

previous line replace beginning of newname until ".txt" (that is, entire value) "c:\path file contains listed names", next line executed way:

move "firstfile.txt" ""c:\path file contains listed names""  

that correctly should move file given path if contains pair of quotes @ each side.

if objective "rename files in folder names listed in text file one-by-one", must merge between 2 lists: file list created dir /b *.txt , name list stored in file.

@echo off setlocal enabledelayedexpansion set old=*.txt set new="c:\path file contains listed names"  < %new% (for /f "tokens=*" %%f in ('dir /b %old%') (    ren read next name redirected input file    set /p newname=    ren "%%f" "!newname!"  )) 

if not want, please describe desired process...


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -