Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the code</p> <pre><code>FOR /R C:\your_folder %%d IN (*.txt) DO ( ren %%d %%~nd.txt_mvd ) </code></pre> <p>%%d is the full file name + path<br> %%~nd return only the file name without the extension<br> Using the /R parameter, it will scan folder and subfolder</p> <p><strong>UPDATE 1</strong></p> <p>The following code should work as required.<br> I've added an IF that ignore the subfolders.</p> <pre><code>FOR /R E:\your_folder\ %%d IN (*.*) DO ( IF %%~dpd==E:\your_folder\ ( ren %%d %%~nd.txt_mvd ) ) </code></pre> <p><strong>UPDATE 2</strong></p> <p>Fixed code</p> <pre><code>FOR /R E:\your_folder\ %%d IN (*.txt) DO ( IF %%~dpd==E:\your_folder\ ( ren %%d %%~nd.txt_mvd ) ) </code></pre> <p><strong>UPDATE 3</strong><br> Here is a more generalized and parametrized version of the script.<br> Change the starting parameter to your need (the first 4 lines of code).<br> This script first rename the files you choose (1st parameter) in your starting folder (3rd parameter), change the extension to the new one (2nd parameter), and then move the renamed files in the folder of your choice (4th parameter).</p> <pre><code>set Extension_of_file_you_want_to_renamne_and_move=txt set New_extension_of_moved_files=txt_mvd set Folder_that_contain_your_files=C:\Your_starting_folder\ set Folder_where_to_move_your_files=C:\Your_destnation_folder\ FOR /R %Folder_that_contain_your_files% %%d IN (*.%Extension_of_file_you_want_to_renamne_and_move%) DO ( IF %%~dpd==%Folder_that_contain_your_files% ( IF %%~xd==.%Extension_of_file_you_want_to_renamne_and_move% ( ren "%%~d" "%%~nd.%New_extension_of_moved_files%" move "%%~dpnd.%New_extension_of_moved_files%" "%Folder_where_to_move_your_files%" ) ) ) </code></pre> <p>when you change the parameter DON'T add any space.<br> So DON'T change the parameter like that:</p> <pre><code>set Folder_that_contain_your_files = c:\myFolder &lt;--- WRONG, WON'T WORK, there are unneeded space </code></pre> <p>instead, write the parameter WITHOUT unneeded space:</p> <pre><code>set Folder_that_contain_your_files=c:\myFolder &lt;--- OK, THIS WILL WORK, there are no extra spaces </code></pre> <p><strong>UPDATE 4</strong><br> Fixed the code, I've added some quotation marks, without them the code wont works if folder name contained spaces.</p> <pre><code>set Extension_of_file_you_want_to_renamne_and_move=txt set New_extension_of_moved_files=txt_mvd set Folder_that_contain_your_files=C:\Your_starting_folder\ set Folder_where_to_move_your_files=C:\Your_destnation_folder\ FOR /R "%Folder_that_contain_your_files%" %%d IN (*.%Extension_of_file_you_want_to_renamne_and_move%) DO ( IF "%%~dpd"=="%Folder_that_contain_your_files%" ( IF %%~xd==.%Extension_of_file_you_want_to_renamne_and_move% ( ren "%%~d" "%%~nd.%New_extension_of_moved_files%" move "%%~dpnd.%New_extension_of_moved_files%" "%Folder_where_to_move_your_files%" ) ) ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload