Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bulk copy with changed extension

35 views
Skip to first unread message

Terry Pinnell

unread,
Feb 20, 2023, 10:50:34 AM2/20/23
to
I have several hundred text files with the extension '.ino'. On my Win
10 PC I can view them in any text editor. They are also accessible on my
iPad because they are in subfolders of my Dropbox folder. However they
cannot be viewed directly on the iPad. One of many frustrations I have
with either iOS or Dropbox - haven't quite pinned the culprit down in
this case.

Could some kind expert please suggest a batch file that would take a
parent folder (File Explorer) path as its input, and make identically
named copies of every .ino file in every subfolder of it, but with a
.txt extension, saving them in the same location.

So files like
C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\My Sketches\MY
SKETCHES 2021-2022\DFR SD ORIG type\JUKEBOX\J26Sh9plus\J26Sh9plus.ino

would be accompanied by
C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\My Sketches\MY
SKETCHES 2021-2022\DFR SD ORIG type\JUKEBOX\J26Sh9plus\J26Sh9plus.txt

If this was a one-off task I would tackle it within File Explorer. I did
so a year ago and it was tedious. But I will want to update it at
intervals, hence the need for some neat automation please.

Any help would be much appreciated.

Auric__

unread,
Feb 20, 2023, 2:22:53 PM2/20/23
to
Terry Pinnell wrote:

> I have several hundred text files with the extension '.ino'. On my Win
> 10 PC I can view them in any text editor. They are also accessible on my
> iPad because they are in subfolders of my Dropbox folder. However they
> cannot be viewed directly on the iPad. One of many frustrations I have
> with either iOS or Dropbox - haven't quite pinned the culprit down in
> this case.

Pretty sure it's iOS.

> Could some kind expert please suggest a batch file that would take a
> parent folder (File Explorer) path as its input, and make identically
> named copies of every .ino file in every subfolder of it, but with a
> .txt extension, saving them in the same location.
[snip]
> If this was a one-off task I would tackle it within File Explorer. I did
> so a year ago and it was tedious. But I will want to update it at
> intervals, hence the need for some neat automation please.
>
> Any help would be much appreciated.

30 seconds of hacking:

if "%%1=" goto :end
cd /D "%%1"
copy /Y *.ino *.txt
for /d /r %%a in (*) do (
cd "%%a"
copy /Y *.ino *.txt )

Note that this *requires* you to tell it what directory to start in. You
could automate that using various methods. (I'm not certain, but I don't
*think* you can just drag a folder onto the batch. I couldn't in 5 seconds
of testing.)

Also, this will prompt you to overwrite any existing .txt files with the
same name, and will stop until you answer. To overwrite without prompting,
remove "/Y" from the "copy" line.

Also also, it'll bitch if any subdirectory doesn't actually contain any
files ending in .ino -- safe to ignore.

--
- Warning, system overload.
- I know!
- Warning, system overload.
- I KNOW! But it must be done!

Kerr-Mudd, John

unread,
Feb 20, 2023, 3:37:28 PM2/20/23
to
--
Bah, and indeed Humbug.

Kerr-Mudd, John

unread,
Feb 20, 2023, 3:39:09 PM2/20/23
to
On Mon, 20 Feb 2023 19:22:51 -0000 (UTC)
"Auric__" <not.m...@email.address> wrote:

I thought /Y suppressed prompts? It does here (WinXP).

> Also also, it'll bitch if any subdirectory doesn't actually contain any
> files ending in .ino -- safe to ignore.
>


--
Bah, and indeed Humbug.

Auric__

unread,
Feb 20, 2023, 4:40:30 PM2/20/23
to
Kerr-Mudd, John wrote:

> On Mon, 20 Feb 2023 19:22:51 -0000 (UTC)
> "Auric__" <not.m...@email.address> wrote:
[snip]
>> copy /Y *.ino *.txt )
[snip]
>> Also, this will prompt you to overwrite any existing .txt files with
>> the same name, and will stop until you answer. To overwrite without
>> prompting, remove "/Y" from the "copy" line.
>
> I thought /Y suppressed prompts? It does here (WinXP).

Argh. Dangit. Yes. I had it backwards in my head, because I'm seriously out
of practice with batches. Absolute brainfart.

Terry: As written, the batch *will* overwrite without prompting. Remove the
"/Y" to make it confirm every overwrite (which is not a bad idea).

--
I think I prefer my evil to be unapologetic.

Terry Pinnell

unread,
Feb 21, 2023, 8:13:57 AM2/21/23
to
Thanks. I do want it to overwrite automatically.

But can you step me through the process to test it please? I assumed I
could run it as it stands, expecting a command window with a prompt for
the target? But a brief flash is all I get.

Auric__

unread,
Mar 1, 2023, 10:26:07 PM3/1/23
to
Terry Pinnell wrote:

[snip]
> But can you step me through the process to test it please? I assumed I
> could run it as it stands, expecting a command window with a prompt for
> the target? But a brief flash is all I get.

(Sorry for the delay replying; life isn't always particularly easy for me.)

The batch does not ask for anything. It's simplest to just run it in the top
folder you want it to work in.

Say you want to copy all .ino files in "C:\Users\terry\Dropbox\Electronics\",
and all subfolders, to .txt files. Put the batch file in that folder and then
just double-click it (or select it and press Enter). You can't pick and
choose which files get copied, nor can you decide which folders to look in --
every .ino file in every subfolder will get copied. Anything more complicated
than that is veering dangerously beyond my attention span, sorry.

--
I'm not sure, but I might want to rephrase that later.

Harry Potter

unread,
Mar 7, 2023, 4:17:33 PM3/7/23
to
__Auric: I see two bugs in your batch file. The first line should read:

if "%%1"=="" goto end

Then you have to end with:

:end
pause

The pause is only necessary if you want to read the batch file's output.

Auric__

unread,
Mar 8, 2023, 6:41:28 PM3/8/23
to
Harry Potter wrote:

> __Auric: I see two bugs in your batch file. The first line should read:
>
> if "%%1"=="" goto end

Pretty much anything would also work here -- I normally have '%1==' in my
batches, not the oopsie I originally posted. As I said, I'm out of practice.

> Then you have to end with:
>
>:end
> pause
>
> The pause is only necessary if you want to read the batch file's output.

It's funny. Lately I've been using certain programming languages that do in
fact have an "end" keyword; that's what threw me off. Batches in fact have
:EOF instead. (On NT systems, anyway; can't remember about 9x or DOS but it
wouldn't surprise me if the answer was "no.")

Also, pause would only necessary if run from the GUI; when run from the
terminal it shouldn't be.

The corrected batch is:

if '%1==' goto :EOF
cd /D "%1"
copy *.ino *.txt
for /d /r %%a in (*) do (
cd "%%a"
copy *.ino *.txt )

The original botched version worked for me, so I had no reason to test
things like "no arguments passed." (As I said, I did the whole thing in 30
seconds.)

--
I have subscribed to this theory for some time.

Harry Potter

unread,
Mar 8, 2023, 7:18:01 PM3/8/23
to
In DOS or Win9X/ME, you have to write a label at the end of the batch file and, if you want to exit immediately, goto there. BTW, AFAIK, you don't have to type the preceding colon in a goto statement.

Kenny McCormack

unread,
Mar 9, 2023, 9:22:48 AM3/9/23
to
In article <XnsAFC1A9C98FA34au...@88.198.57.247>,
Auric__ <not.m...@email.address> wrote:
>Harry Potter wrote:
>
>> __Auric: I see two bugs in your batch file. The first line should read:
>>
>> if "%%1"=="" goto end
>
>Pretty much anything would also work here -- I normally have '%1==' in my
>batches, not the oopsie I originally posted. As I said, I'm out of practice.
>
>> Then you have to end with:
>>
>>:end
>> pause
>>
>> The pause is only necessary if you want to read the batch file's output.
>
>It's funny. Lately I've been using certain programming languages that do in
>fact have an "end" keyword; that's what threw me off. Batches in fact have
>:EOF instead. (On NT systems, anyway; can't remember about 9x or DOS but it
>wouldn't surprise me if the answer was "no.")

Because "end" looks too much like it might be a keyword (even if it isn't),
I got in the habit of making my "end of the batch" label be ":the_end".

I got into this habit back in DOS/Win9x days, and have stuck with it. Of
course, in modern NT (CMD) days, it's not really necessary, since you can
just do: goto :EOF

BTW, yes, the colon is technically not necessary, but many batch writers
like to see it anyway, since it matches up with the label itself. Just
personal preference, of course, but I think it actually documented (in some
help file) that way.

>Also, pause would only necessary if run from the GUI; when run from the
>terminal it shouldn't be.

Correct. And it is an ugly hack, but one that has gained currency because
a lot of people don't deal with the command line. You even see this trope in
"regular" languages, like VB Basic, etc - people put in a "Press any key to
continue" followed by some form of "getkey()" in their VB programs, for
precisely this reason - so that if it is run inside some GUI, well, you
know the rest...

>The corrected batch is:
>
> if '%1==' goto :EOF
> cd /D "%1"
> copy *.ino *.txt
> for /d /r %%a in (*) do (
> cd "%%a"
> copy *.ino *.txt )
>
>The original botched version worked for me, so I had no reason to test
>things like "no arguments passed." (As I said, I did the whole thing in 30
>seconds.)

FWIW, I might do it like this (instead of testing %1 directly on its own
line):

cd /D "%1" || (
echo Arg is missing or invalid!
goto :EOF
)

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/DanaC

Kenny McCormack

unread,
Mar 9, 2023, 9:25:19 AM3/9/23
to
In article <2534364e-c495-467f...@googlegroups.com>,
Harry Potter <rose.j...@yahoo.com> wrote:
>In DOS or Win9X/ME, you have to write a label at the end of the batch file
>and, if you want to exit immediately, goto there.

Correct. But not much relevant nowadays. Does anyone still use (or need
to program compatibly for) those platforms?

Note: I'm all for retro-computing - I still run XP - but even that is 20
years old now.

>BTW, AFAIK, you don't have to type
>the preceding colon in a goto statement.

Correct. Either way works. Some people like to see the : there anyway.

--
You are a dreadful man, Kenny, for all your ways are the ways of death.
- Rick C Hodgin -

(P.S. -> https://www.youtube.com/watch?v=sMmTkKz60W8)

Zaidy036

unread,
Mar 9, 2023, 3:06:35 PM3/9/23
to
On 3/9/2023 9:22 AM, Kenny McCormack wrote:
> if "%%1"=="" goto end
why not just
if "%%1"=="" Exit or if "%%1"=="" cmd /k ?

Auric__

unread,
Mar 16, 2023, 6:12:27 PM3/16/23
to
Kenny McCormack wrote:

> In article <2534364e-c495-467f...@googlegroups.com>,
> Harry Potter <rose.j...@yahoo.com> wrote:
>>In DOS or Win9X/ME, you have to write a label at the end of the batch file
>>and, if you want to exit immediately, goto there.
>
> Correct. But not much relevant nowadays. Does anyone still use (or need
> to program compatibly for) those platforms?
>
> Note: I'm all for retro-computing - I still run XP - but even that is 20
> years old now.

FreeDOS might have something to say about that. v1.3 released 20 February
2022. Just sayin'.

But yes, I do in fact still use DOS on a regular basis, and even program for
it. (Windows 9x, not so much.) I'm currently working on an app that will
include a DOS release, alongside Windows, Linux, MacOS, BSD, OS/2, Android,
and iOS. (Why? Because I use all of them. And because I can.)

--
Death might be preferable to amnesia combined with prophetic knowledge.

Kenny McCormack

unread,
Mar 16, 2023, 6:28:28 PM3/16/23
to
In article <XnsAFC99AB1DB79Dau...@88.198.57.247>,
Auric__ <not.m...@email.address> wrote:
...
>But yes, I do in fact still use DOS on a regular basis, and even program
>for it. (Windows 9x, not so much.) I'm currently working on an app that
>will include a DOS release, alongside Windows, Linux, MacOS, BSD, OS/2,
>Android, and iOS. (Why? Because I use all of them. And because I can.)

Cool!

--
This is the GOP's problem. When you're at the beginning of the year
and you've got nine Democrats running for the nomination, maybe one or
two of them are Dennis Kucinich. When you have nine Republicans, seven
or eight of them are Michelle Bachmann.
0 new messages