2

I am using XCOPY the following successfully copies the entire contents of \MY SKETCHES 2021 to \My Sketches (TEXT).

This is my command:
xcopy C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\My Sketches\MY SKETCHES 2021 C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\My Sketches\My Sketches (TEXT) /E

But I want to change the extension of all .ino source files to .txt. Ideally simultaneously, but I'd be happy enough with two steps, perhaps the second being a RENAME. I see no relevant parameter in XCOPY. And the versatile Bulk Rename Utility works only on a single folder, not recursively.

Background: this will allow me to view the .ino files on my iPad with Dropbox, which cannot do that despite their being plain text files.
All suggestions gratefully received please.

1 Answer 1

0

This seems to work:

for /F "usebackq delims=" %F in (`"dir /b/s *.ino"`) do  ren "%F" "%~nF.txt"

The usebackq is needed to allow the back quotes in the file set. The delims= is for folders or filenames with embedded spaces. The %~nF expands %F to a file name only, without path or extension. To check it before you run it, just insert an echo e.g.

for /F "usebackq delims=" %F in (`"dir /b/s *.ino"`) do echo ren "%F" "%~nF.txt"

Edit: That works when entered on a command prompt. In a batch script, it is necessary to double the percent signs e.g.

for /F "usebackq delims=" %%F in (`"dir /b/s *.ino"`) do echo ren "%%F" "%%~nF.txt"
3
  • Many thanks, appreciate the fast response. It's a few decades since I used batch files so that's almost certainly why I couldn't get that to work. I assumed the only thing to change was 'dir'. My batch file is this therefore this one-liner: for /F "usebackq delims=" %F in ("C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES - part copy /b/s *.ino") do ren "%F" "%~nF.txt"
    – user263358
    Commented Oct 26, 2021 at 14:49
  • Why such a short time to edit?
    – user263358
    Commented Oct 26, 2021 at 14:57
  • Tried this version too: for /F "usebackq delims=" %%F in ("C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES - part copy /b/s *.ino") do echo ren "%%F" "%%~nF.txt" Also tried the earlier one from command prompt, but got The system cannot find the file C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES - part copy /b/s *.ino.
    – user263358
    Commented Oct 26, 2021 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .