Discussion:
Bulk copy with changed extension
(too old to reply)
Terry Pinnell
2023-02-20 15:51:19 UTC
Permalink
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__
2023-02-20 19:22:51 UTC
Permalink
Post by Terry Pinnell
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.
Post by Terry Pinnell
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]
Post by Terry Pinnell
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
2023-02-20 20:37:26 UTC
Permalink
On Mon, 20 Feb 2023 19:22:51 -0000 (UTC)
Post by Auric__
Post by Terry Pinnell
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.
Post by Terry Pinnell
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]
Post by Terry Pinnell
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.
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!
--
Bah, and indeed Humbug.
Kerr-Mudd, John
2023-02-20 20:39:06 UTC
Permalink
On Mon, 20 Feb 2023 19:22:51 -0000 (UTC)
Post by Auric__
Post by Terry Pinnell
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.
Post by Terry Pinnell
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]
Post by Terry Pinnell
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.
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.
I thought /Y suppressed prompts? It does here (WinXP).
Post by Auric__
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__
2023-02-20 21:40:28 UTC
Permalink
Post by Kerr-Mudd, John
On Mon, 20 Feb 2023 19:22:51 -0000 (UTC)
[snip]
Post by Kerr-Mudd, John
Post by Auric__
copy /Y *.ino *.txt )
[snip]
Post by Kerr-Mudd, John
Post by Auric__
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
2023-02-21 13:14:42 UTC
Permalink
Post by Auric__
Post by Kerr-Mudd, John
On Mon, 20 Feb 2023 19:22:51 -0000 (UTC)
[snip]
Post by Kerr-Mudd, John
Post by Auric__
copy /Y *.ino *.txt )
[snip]
Post by Kerr-Mudd, John
Post by Auric__
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).
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__
2023-03-02 03:26:03 UTC
Permalink
Terry Pinnell wrote:

[snip]
Post by Terry Pinnell
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
2023-03-07 21:17:31 UTC
Permalink
__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__
2023-03-08 23:41:26 UTC
Permalink
Post by Harry Potter
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.
Post by Harry Potter
: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
2023-03-09 00:18:00 UTC
Permalink
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
2023-03-09 14:25:17 UTC
Permalink
Post by Harry Potter
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.
Post by Harry Potter
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. ->

Auric__
2023-03-16 22:12:25 UTC
Permalink
Post by Kenny McCormack
Post by Harry Potter
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
2023-03-16 22:28:25 UTC
Permalink
In article <***@88.198.57.247>,
Auric__ <***@email.address> wrote:
...
Post by Auric__
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.
Kenny McCormack
2023-03-09 14:22:46 UTC
Permalink
Post by Auric__
Post by Harry Potter
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.
Post by Harry Potter
: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.
Post by Auric__
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...
Post by Auric__
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
Zaidy036
2023-03-09 20:06:34 UTC
Permalink
Post by Harry Potter
if "%%1"=="" goto end
why not just
if "%%1"=="" Exit or if "%%1"=="" cmd /k ?
Loading...