![]() ![]() %~xI expands %I to a file extension only [. %~nI expands %I to a file name only [ My file %~pI expands %I to a path only [ \Documents and Settings\k_2K.MYDOMAIN\My Documents\log file folder %~dI expands %I to a drive letter only [ C: %~fI expands %I to a fully qualified path name [ C:\Documents and Settings\k_2K.MYDOMAIN\My Documents\log file folder\My file.doc %~I expands %I which removes any surrounding quotes (") [ My file.doc Variable (with modifier) Description [ example Using %I="My file.doc" from the above folder in the table: The table assumes we are going to type these all at the command prompt, so all %%I becomes %I To use those in a command and allow for the spaces, we have to remember to use quotes, as in:Įcho if not exist "%%~dpG\1.mpg" ren "%%~fG" 1.mpg ![]() Would expands %%G as a full file name depending on the path it is in, and display something like this:Ĭ:\Documents and Settings\k_2K.MYDOMAIN\My Documents\log file folder\My file.doc So now as we use %zfn% the quotes are not in our way. When the for loop sets %%G to "My file.doc" the following line:Įxpands %%G without the surrounding quotes before running the command: In a FOR loop, you can do as bill did and set the variable you need to the modified version of the replaceable parameter: Variables generated by a FOR command become replaceable parameters and can use modifiers. As a special note modifiers do not work on %* although it is a usage of replaceable parameters. Replaceable parameters are the command line addressable variables like %0 and %1. They ONLY work on replaceable parameters. I'm only starting with the hard part so as you try the examples on the command line you'll know why they don't work.įirst thing to note is modifiers do NOT work on normal variables. This is more to assist in generating and modifying new code for other needs by understanding modifyers. :: remove the echo next line to perform the rename.īill's code probly answers what you need tho i haven't time to test it. :: directory list MINUS lines beginning with SPACE, EXCEPT ".mpg" linesįor /f "delims=" %%G in ('dir/b "%zdp%\*.*"^|findstr /r /v /c:"^ "^|findstr /i /v ".mpg"') do ( :: change the value assigned to zdp to change directory being processed This batch tested on XP, but should work on NT/2K/XP. To actually rename, remove the 'echo' from the line indicated. The following will merely report to the screen the names of the files where the NAME is changed. If you want to rename in a directory other than F:\a then change the "set zdp=" line (directory processed) to the new name required, but without a trailing "\" * rename any files to existingname.mpg if that is possible If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string %~$PATH:I searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. %~aI expands %I to the file attributes of file %~sI expands path to contain short names only %~fI expands %I to a fully qualified path name %~I expands %I which removes any surrounding quotes (") Or any name like abcd.mpg 154.mpg 5trsw.mpgĬan any body explain and example any one from this ? and what is the meaning of I have folder named f:\a contains the followinf files :Īnd want to rename the files to be like this :
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |