Discussion:
Copying to SD card sequentially
(too old to reply)
Terry Pinnell
2023-10-25 10:19:59 UTC
Permalink
This will probably seem a rather obscure request. I need to find a way
to sequentially copy all the files from folder A to folder B. Trivial?
Unfortunately it seems not.

Folder B is an SD card (actually a micro-SD, various sizes). I don't
want to distract or bore with detail, but it's in a little module, 'DFR
Mini MP3 Player' from DF Robot in China.
https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299

The module somehow 'indexes' the files in the order in which they are
transferred to the card. So that 002.mp3 must arrive in folder B after
001.mp3, and so on.

I'd always assumed this would be done automatically by Windows 10 File
Explorer. But to my dismay it clearly isn't so. Merely sorting folder A
into filename order
0001.mp3
0002.mp3
.
.
0123.mp3
and then using whatever combination of familiar steps in File Explorer I
try (wholesale copy/pasting, dragging, selecting from first or last
file, resetting attributes with other utilities, renaming, resorting,
etc) does not work consistently.

Even if I apparently get a winning combination, any subsequent change
(like adding 0124.mp3 after 0123.mp3) is not always reflected as
intuition would expect.

I'm considering resorting to using my Macro Express Pro application, to
simulate one-by-one dragging, but I know it would be painfully slow.
Right now, to proceed with my project, I have a mere 150 files, so I'll
tediously do it manually after (Fully, not Quick) formatting the card.
But I hope a batch file can cut the mustard please.

Or does anyone know of a property/attribute that can be changed on the
PC before copying, that will have the required 'sequential indexing'
effect?

Terry
R.Wieser
2023-10-25 11:12:22 UTC
Permalink
Terry,
Post by Terry Pinnell
Or does anyone know of a property/attribute that can be changed on
the PC before copying, that will have the required 'sequential
indexing' effect?
Alas, no.

It looks like the files are copied in the order in which they where put onto
the disk. If you want to see that order, open a console window and do a
"dir *.mp3". To *show* them in the order Explorer (by default) uses, use
"dir /one *.mp3"

You might want to use "dir /one /b *.mp3 > filelist.txt" to put a sorted
list of (just the) filenames into a file, and than iterate thru the names in
that file and copy them one-by-one :

- - - - - - -

@echo off
for /f "tokens=*" %%a in (filelist.txt) do (
echo line=%%a
)
- - - - - - -

(replace the "echo line=" part with the apropriate "copy" command)

Hope that helps.

Regards,
Rudy Wieser
Terry Pinnell
2023-10-25 11:52:07 UTC
Permalink
Post by R.Wieser
Terry,
Post by Terry Pinnell
Or does anyone know of a property/attribute that can be changed on
the PC before copying, that will have the required 'sequential
indexing' effect?
Alas, no.
It looks like the files are copied in the order in which they where put onto
the disk. If you want to see that order, open a console window and do a
"dir *.mp3". To *show* them in the order Explorer (by default) uses, use
"dir /one *.mp3"
You might want to use "dir /one /b *.mp3 > filelist.txt" to put a sorted
list of (just the) filenames into a file, and than iterate thru the names in
- - - - - - -
@echo off
for /f "tokens=*" %%a in (filelist.txt) do (
echo line=%%a
)
- - - - - - -
(replace the "echo line=" part with the apropriate "copy" command)
Hope that helps.
Regards,
Rudy Wieser
Thanks, appreciate the fast reply. I've never used a 'console window'
before, but read:

"To open the Console, press Ctrl+Shift+J (Windows, Linux) or
Command+Option+J".

Can you amplify a little please? Starting with when and where I should
use that hotkey? In parallel, after lunch, I'll do some more thorough
googling about 'the console window'.

Terry
R.Wieser
2023-10-25 12:37:41 UTC
Permalink
Terry,
Post by Terry Pinnell
Thanks, appreciate the fast reply.
You where just lucky, there was no intention on my part. :-)
Post by Terry Pinnell
"To open the Console, press Ctrl+Shift+J (Windows, Linux)
or Command+Option+J".
It seems my OS is a bit older than yours, as it doesn't respond to that
combination of keys.
Post by Terry Pinnell
Can you amplify a little please? Starting with when and where I should
use that hotkey?
Alas, I'm unable to do so.

On my 'puter I just click "start" -> "programs" -> "Accessories", and in
that list I select "command prompt" (black bordered icon with "C:\" in it).

Though you might be able to find/start it by typing "cmd.exe" in the Win10
"run" dialog (Windows + R).

... and I just found a whole list of how to do it :

https://www.howtogeek.com/235101/10-ways-to-open-the-command-prompt-in-windows-10/
Post by Terry Pinnell
In parallel, after lunch, I'll do some more thorough googling about
'the console window'.
Thats not the worst thing you could do. :-)


I must say I just assumed you already knew how to work with the commandline
interface and Batch, due to you posting here. But if you run into problems
with what I've shown you than just holler.

By the way, you might also take a peek at "powershell"* I've been told its
quite abit more capable than what Batch offers (but can't confirm as I've
never used it).

* https://www.howtogeek.com/662611/9-ways-to-open-powershell-in-windows-10/

Regards,
Rudy Wieser
Terry Pinnell
2023-10-25 12:55:37 UTC
Permalink
Post by R.Wieser
Terry,
Post by Terry Pinnell
Thanks, appreciate the fast reply.
You where just lucky, there was no intention on my part. :-)
Post by Terry Pinnell
"To open the Console, press Ctrl+Shift+J (Windows, Linux)
or Command+Option+J".
It seems my OS is a bit older than yours, as it doesn't respond to that
combination of keys.
Post by Terry Pinnell
Can you amplify a little please? Starting with when and where I should
use that hotkey?
Alas, I'm unable to do so.
On my 'puter I just click "start" -> "programs" -> "Accessories", and in
that list I select "command prompt" (black bordered icon with "C:\" in it).
Though you might be able to find/start it by typing "cmd.exe" in the Win10
"run" dialog (Windows + R).
https://www.howtogeek.com/235101/10-ways-to-open-the-command-prompt-in-windows-10/
Post by Terry Pinnell
In parallel, after lunch, I'll do some more thorough googling about
'the console window'.
Thats not the worst thing you could do. :-)
I must say I just assumed you already knew how to work with the commandline
interface and Batch, due to you posting here. But if you run into problems
with what I've shown you than just holler.
By the way, you might also take a peek at "powershell"* I've been told its
quite abit more capable than what Batch offers (but can't confirm as I've
never used it).
* https://www.howtogeek.com/662611/9-ways-to-open-powershell-in-windows-10/
Regards,
Rudy Wieser
OK, by 'console window' I thought you meant what I understand is the
Microsoft Management Console.

I'm familiar with the Command Prompt window and also sometimes use the
PowerShell windows in copy/paste mode successfully

Perhaps someone can suggest a solution using either of those instead of
a batch file please?

P.S.
I've also now opened a thread in the PowerShell Forum:
https://forums.powershell.org/t/novice-copying-files-sequentially-to-sd-card/23043/2
R.Wieser
2023-10-25 14:18:56 UTC
Permalink
Terry,
Post by Terry Pinnell
OK, by 'console window' I thought you meant what I understand is the
Microsoft Management Console.
Nope. Not by a long shot.
Post by Terry Pinnell
I'm familiar with the Command Prompt window and also sometimes use the
PowerShell windows in copy/paste mode successfully
Perhaps someone can suggest a solution using either of those instead
of a batch file please?
You're not making much sense there : A batch script runs in a "Command
Prompt window". IOW, you need the latter to be able to execute the former.

Also, if you do *not* want a batch script than you're posting in the wrong
newsgroupv I'm afraid.

Regards,
Rudy Wieser
Terry Pinnell
2023-10-25 16:14:01 UTC
Permalink
Post by R.Wieser
Terry,
Post by Terry Pinnell
OK, by 'console window' I thought you meant what I understand is the
Microsoft Management Console.
Nope. Not by a long shot.
I've never heard the Command Prompt window called the 'console window'
before.
Post by R.Wieser
Post by Terry Pinnell
I'm familiar with the Command Prompt window and also sometimes use the
PowerShell windows in copy/paste mode successfully
Perhaps someone can suggest a solution using either of those instead
of a batch file please?
You're not making much sense there : A batch script runs in a "Command
Prompt window".
IOW, you need the latter to be able to execute the former.
Yes - so why call it a 'console window'?
Post by R.Wieser
Also, if you do *not* want a batch script than you're posting in the wrong
newsgroupv I'm afraid.
I think the last two sentences of my initial post made sense. I hoped
for a batch solution but I'd be happy with any.
R.Wieser
2023-10-25 18:12:29 UTC
Permalink
Terry,
Post by Terry Pinnell
I've never heard the Command Prompt window called the 'console
window' before.
But you know Linux ? And yet you didn't recognise the phrase ? Weird.

You know, I'm getting the feeling you're playing a "lets play stupid" game
with me, and I can't say I appreciate it.

You post in a Batch newsgroup, but when you pretty-much get the solution on
a silver platter you ignore it.
Post by Terry Pinnell
I think the last two sentences of my initial post made sense.
I hoped for a batch solution but I'd be happy with any.
I gave you the parts for one one. Stick them together and you got your
solution. Or don't. Your choice.

I even indicated that if you would run into a problem you only needed to
holler. I retract that offer. Find somebody else.

Goodbye.

Regards,
Rudy Wieser
Tom Del Rosso
2023-11-27 06:59:06 UTC
Permalink
Post by Terry Pinnell
Yes - so why call it a 'console window'?
It simulates the screen of a dumb terminal, aka a console.

The 'con' device is the combination of keyboard and screen under DOS, or
keyboard and console window under Windows.

A dumb terminal is an input and output device, so the keyboard and
screen combine to make a virtual single device that does the same job.
--
Defund the Thought Police
Herbert Kleebauer
2023-10-25 11:53:36 UTC
Permalink
Post by Terry Pinnell
I'd always assumed this would be done automatically by Windows 10 File
Explorer. But to my dismay it clearly isn't so. Merely sorting folder A
into filename order
0001.mp3
0002.mp3
.
.
0123.mp3
and then using whatever combination of familiar steps in File Explorer I
try (wholesale copy/pasting, dragging, selecting from first or last
file, resetting attributes with other utilities, renaming, resorting,
etc) does not work consistently.
If you select all files with <ctrl>-A and then use the mouse
to drag and drop, the files to a different folder, then
the file selected is copied first and then the remaining
files.

So if you select 0078.mp3 for drag and drop, the copy order is

0078.mp3 0079.mp3 .... 0123.mp3 0001.mp3 .....0077.mp3

So in your case, select 0001.mp3 for drag and drop.
Terry Pinnell
2023-10-25 12:21:33 UTC
Permalink
Post by Herbert Kleebauer
Post by Terry Pinnell
I'd always assumed this would be done automatically by Windows 10 File
Explorer. But to my dismay it clearly isn't so. Merely sorting folder A
into filename order
0001.mp3
0002.mp3
.
.
0123.mp3
and then using whatever combination of familiar steps in File Explorer I
try (wholesale copy/pasting, dragging, selecting from first or last
file, resetting attributes with other utilities, renaming, resorting,
etc) does not work consistently.
If you select all files with <ctrl>-A and then use the mouse
to drag and drop, the files to a different folder, then
the file selected is copied first and then the remaining
files.
So if you select 0078.mp3 for drag and drop, the copy order is
0078.mp3 0079.mp3 .... 0123.mp3 0001.mp3 .....0077.mp3
So in your case, select 0001.mp3 for drag and drop.
As I said, that's what you would expect.

As I also said, it doesn't work.
Herbert Kleebauer
2023-10-25 14:11:03 UTC
Permalink
Post by Terry Pinnell
Post by Herbert Kleebauer
If you select all files with <ctrl>-A and then use the mouse
to drag and drop, the files to a different folder, then
the file selected is copied first and then the remaining
files.
So if you select 0078.mp3 for drag and drop, the copy order is
0078.mp3 0079.mp3 .... 0123.mp3 0001.mp3 .....0077.mp3
So in your case, select 0001.mp3 for drag and drop.
As I said, that's what you would expect.
As I also said, it doesn't work.
I think the explorer works this way.

In the source directory enter this command
(replace d:\ with your destination; when used
in a batch you have to use %%i instead of %i):

for /f %i in ('dir /b /on *.mp3') do copy %i d:\

If you still get the wrong order, it is bot because
of the copy process but the destination directory.
First erase the destination directory and then create
it again. Or if it is the root directory, format
the SD card before copying the files.
Robert Roland
2023-10-26 21:50:31 UTC
Permalink
Post by Herbert Kleebauer
for /f %i in ('dir /b /on *.mp3') do copy %i d:\
It may be worth noting that if you want to use this in a batch file,
the percent signs must be doubled.
--
RoRo
JJ
2023-10-25 12:37:16 UTC
Permalink
Post by Terry Pinnell
This will probably seem a rather obscure request. I need to find a way
to sequentially copy all the files from folder A to folder B. Trivial?
Unfortunately it seems not.
Folder B is an SD card (actually a micro-SD, various sizes). I don't
want to distract or bore with detail, but it's in a little module, 'DFR
Mini MP3 Player' from DF Robot in China.
https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
The module somehow 'indexes' the files in the order in which they are
transferred to the card. So that 002.mp3 must arrive in folder B after
001.mp3, and so on.
I'd always assumed this would be done automatically by Windows 10 File
Explorer. But to my dismay it clearly isn't so. Merely sorting folder A
into filename order
0001.mp3
0002.mp3
..
..
0123.mp3
and then using whatever combination of familiar steps in File Explorer I
try (wholesale copy/pasting, dragging, selecting from first or last
file, resetting attributes with other utilities, renaming, resorting,
etc) does not work consistently.
Even if I apparently get a winning combination, any subsequent change
(like adding 0124.mp3 after 0123.mp3) is not always reflected as
intuition would expect.
I'm considering resorting to using my Macro Express Pro application, to
simulate one-by-one dragging, but I know it would be painfully slow.
Right now, to proceed with my project, I have a mere 150 files, so I'll
tediously do it manually after (Fully, not Quick) formatting the card.
But I hope a batch file can cut the mustard please.
Or does anyone know of a property/attribute that can be changed on the
PC before copying, that will have the required 'sequential indexing'
effect?
Terry
It's all mainly because all SD cards and thumb drives are preformatted with
FAT-n file system, and FAT file system is not an indexed file system. i.e.
has physical index to directory entries.

FAT file system is basically an unordered file system. And the FAT file
system specification doesn't state that, the directory entries should be
physically sorted. It also doesn't state that all implementers should sort
the directory entries after they're retrieved. And there's a good reason why
systems don't update a list of directory entries in order to physically sort
it.

Unfortunately, there no system setting to always sort the list of directory
entries retrived from FAT file systems.
Terry Pinnell
2023-10-25 13:00:42 UTC
Permalink
Post by JJ
Post by Terry Pinnell
This will probably seem a rather obscure request. I need to find a way
to sequentially copy all the files from folder A to folder B. Trivial?
Unfortunately it seems not.
Folder B is an SD card (actually a micro-SD, various sizes). I don't
want to distract or bore with detail, but it's in a little module, 'DFR
Mini MP3 Player' from DF Robot in China.
https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
The module somehow 'indexes' the files in the order in which they are
transferred to the card. So that 002.mp3 must arrive in folder B after
001.mp3, and so on.
I'd always assumed this would be done automatically by Windows 10 File
Explorer. But to my dismay it clearly isn't so. Merely sorting folder A
into filename order
0001.mp3
0002.mp3
..
..
0123.mp3
and then using whatever combination of familiar steps in File Explorer I
try (wholesale copy/pasting, dragging, selecting from first or last
file, resetting attributes with other utilities, renaming, resorting,
etc) does not work consistently.
Even if I apparently get a winning combination, any subsequent change
(like adding 0124.mp3 after 0123.mp3) is not always reflected as
intuition would expect.
I'm considering resorting to using my Macro Express Pro application, to
simulate one-by-one dragging, but I know it would be painfully slow.
Right now, to proceed with my project, I have a mere 150 files, so I'll
tediously do it manually after (Fully, not Quick) formatting the card.
But I hope a batch file can cut the mustard please.
Or does anyone know of a property/attribute that can be changed on the
PC before copying, that will have the required 'sequential indexing'
effect?
Terry
It's all mainly because all SD cards and thumb drives are preformatted with
FAT-n file system, and FAT file system is not an indexed file system. i.e.
has physical index to directory entries.
FAT file system is basically an unordered file system. And the FAT file
system specification doesn't state that, the directory entries should be
physically sorted. It also doesn't state that all implementers should sort
the directory entries after they're retrieved. And there's a good reason why
systems don't update a list of directory entries in order to physically sort
it.
Unfortunately, there no system setting to always sort the list of directory
entries retrived from FAT file systems.
Many thanks, that's enlightening - although obviously disappointing!

The most frustrating aspect is the inconsistency. I *have* manage to get
the files on the card recognised in the order I arranged them in File
Explorer. But not reliably...

As mentioned up thread, I've also raised the issue here:
https://forums.powershell.org/t/novice-copying-files-sequentially-to-sd-card/23043/2

Terry
Robert Roland
2023-10-26 21:57:43 UTC
Permalink
On Wed, 25 Oct 2023 14:00:42 +0100, Terry Pinnell
Post by Terry Pinnell
powershell.org
In PowerShell, this should should work (not fully tested, all on one
line):

Get-ChildItem -Path "C:\FolderA" -Filter "*.mp3" | Sort-Object
-Property Name | ForEach-Object -Process {Copy-Item -Path $_
-Destination "C:\FolderB\"}
--
RoRo
Terry Pinnell
2023-10-27 11:04:40 UTC
Permalink
Post by Robert Roland
On Wed, 25 Oct 2023 14:00:42 +0100, Terry Pinnell
Post by Terry Pinnell
powershell.org
In PowerShell, this should should work (not fully tested, all on one
Get-ChildItem -Path "C:\FolderA" -Filter "*.mp3" | Sort-Object
-Property Name | ForEach-Object -Process {Copy-Item -Path $_
-Destination "C:\FolderB\"}
Thanks Robert. I've only occasionally used PowerShell, and then only in
copy/paste mode, so I expect I've not correctly edited your script:

Yours:
Get-ChildItem -Path "C:\FolderA" -Filter "*.mp3" | Sort-Object-Property
Name | ForEach-Object -Process {Copy-Item -Path $_-Destination
"C:\FolderB\"}

My paths are:
Source = "C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1"
Destination = "L:\" (USB drive with an SD card holding my FAT-32 micro
SD card).

So this is what I tried:
Get-ChildItem -Path
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" |
Sort-Object-Property Name | ForEach-Object -Process {Copy-Item -Path
$_-Destination "L:\"}

This was the error message:

Get-ChildItem -Path
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" |
Sort-Object-Property Name | ForEach-Object -Process {Copy-Item -Path
$_-Destination "L:\"}
Sort-Object-Property : The term 'Sort-Object-Property' is not recognized
as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
At line:1 char:143
+ ... \TalkingTemp Proj\_MP3 _files\FromL-1" | Sort-Object-Property Name
| ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound:
(Sort-Object-Property:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Terry
Robert Roland
2023-10-27 12:11:33 UTC
Permalink
On Fri, 27 Oct 2023 12:04:40 +0100, Terry Pinnell
Post by Terry Pinnell
The term 'Sort-Object-Property' is not recognized
as the name of a cmdlet, function, script file, or operable program.
There is a space missing after the Sort-Object.

-Property is a parameter for the Sort-Object cmdlet.
--
RoRo
Terry Pinnell
2023-10-27 15:25:27 UTC
Permalink
Post by Robert Roland
On Fri, 27 Oct 2023 12:04:40 +0100, Terry Pinnell
Post by Terry Pinnell
The term 'Sort-Object-Property' is not recognized
as the name of a cmdlet, function, script file, or operable program.
There is a space missing after the Sort-Object.
-Property is a parameter for the Sort-Object cmdlet.
Thanks Robert, that successfully copied. But as usual the card (which
was a fresh one) did not then play from 0001 to 0137. Given its
previously virgin state that's particularly odd.

I'll report my detailed next steps in case it offers clues, prompts
further insights, etc.

I removed the card, ran a Quick Format and repeated the command prompt.
But no change.

I noted that L:\ in File explorer reports at its bottom that there are
133 items, not 137. Examination showed that while the first was 0001 and
the last 0137, there were actually 136 files, because 0134 was absent.
All 137 in the source were correct, of course.

Also track 101 looked suspiciously short in duration. To ensure that
wasn't one of the causes I edited and renamed it.

I did another QF and ran the command again. In FE L: was still was
incorrect; still reporting 133 files - and 0101 was not one of them!

--------------------

After another QF I turned to FE, selected the 137 in the source and
dragged them to L: They all looked 'correct' and all 137 are reported.

And - a rare success - they all played 137 correctly.

I did then look more closely at the source files.
They do not all have the same reported Date created, dispelling my
earlier assumption that they should have.

I think the bottom line is simply to get the files in the order required
(0001, 0002, etc), and ensure they are copied with FE in that physical
order. As to HOW to ensure that with 100% reliability, I'm now
reasonably confident it is just a matter of repeating the steps I
described above. With particular attention to the points Herbert
emphasised: dragging (not copy/pasting), and at the start of the drag
positioning the mouse cursor in the first file, i.e. near the top of the
source selection. The warning message I described earlier indicates file
0001 if that was done right.

This was the command prompt I used:

for /f %i in ('dir /on /b
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1\*.mp3"')
do copy "C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1\%i" L:\
Ammammata
2023-10-25 15:29:17 UTC
Permalink
Post by JJ
FAT file system is basically an unordered file system. And the FAT file
system specification doesn't state that, the directory entries should be
physically sorted.
I remember one of the Norton Utilities did the job, ages ago, so you
could get file sorted using DIR and no parameters, also because in the
first MSDOS releases the sort option wasn't available

here the manual of version 1.1 by Compaq

DIR (DIRECTORY) Command
Type: Internal .
Purpose: To list a directory of the files on a diskette .
Syntax: [d :]DIR [filespec] [/P] [/W]
Comments : If no parameter is present, all directory entries on the
diskette in the default drive are listed .
If only the drive specification is present (DIR d :), all
entries on the diskette in the specified drive are
listed . etc etc
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........
Terry Pinnell
2023-10-25 16:17:35 UTC
Permalink
Post by Ammammata
Post by JJ
FAT file system is basically an unordered file system. And the FAT file
system specification doesn't state that, the directory entries should be
physically sorted.
I remember one of the Norton Utilities did the job, ages ago, so you
could get file sorted using DIR and no parameters, also because in the
first MSDOS releases the sort option wasn't available
here the manual of version 1.1 by Compaq
DIR (DIRECTORY) Command
Type: Internal .
Purpose: To list a directory of the files on a diskette .
Syntax: [d :]DIR [filespec] [/P] [/W]
Comments : If no parameter is present, all directory entries on the
diskette in the default drive are listed .
If only the drive specification is present (DIR d :), all
entries on the diskette in the specified drive are
listed . etc etc
Thanks, I was a keen NU user decades ago but I suspect a lengthy
digression if I risk pursuing it again now for this issue ;-)
JJ
2023-10-25 19:17:09 UTC
Permalink
Post by Terry Pinnell
Thanks, I was a keen NU user decades ago but I suspect a lengthy
digression if I risk pursuing it again now for this issue ;-)
For Windows, there are tools for sorting directory entries in FAT drives.

Below two pages which were top 2 from Google search, mention the tools.

https://softwarerecs.stackexchange.com/q/19575

https://superuser.com/q/376577

Don't bother trying solutions which are based on or require Python or any
other *nix scripting tools. It's just too much hassle to prepare.

There'll be two kinds of this tool. One which use direct disk access, and
one which don't.

Those which use direct disk access are much faster than the other kind, but
will require dismounting the file system first. The file system will not be
accessible while it's being sorted.

Those which don't use direct disk access, are much slower than the other
kind, because it moves files/subdirectories around to achieve sorted
directory entries. This one kind is not recommended for non magnetic/platter
drives, because it will perform lots of disk writes depending on the number
of used directory entries.
R.Wieser
2023-10-26 06:43:40 UTC
Permalink
JJ,
Post by JJ
For Windows, there are tools for sorting directory entries
in FAT drives.
A tool for sorting a directory ? For something that a small batch script
can do as wel ?

1) Move the to-be-sorted files to a temp directory (on the same drive*)

2) Create a sorted list of the files in the temp directory

3) Read the sorted list and move the files one-by-one back to the origional
directory

* moving on the same drive just moves the metadata, not the contents of the
file.

Total number of lines in the batch file : 7, if you include creating and
removing the temp directory.

If you want to have the folders at the top (File Explorer style) it only
takes a single extra line.

Regards,
Rudy Wieser
Terry Pinnell
2023-10-26 08:31:38 UTC
Permalink
Post by R.Wieser
JJ,
Post by JJ
For Windows, there are tools for sorting directory entries
in FAT drives.
A tool for sorting a directory ? For something that a small batch script
can do as wel ?
1) Move the to-be-sorted files to a temp directory (on the same drive*)
2) Create a sorted list of the files in the temp directory
3) Read the sorted list and move the files one-by-one back to the origional
directory
* moving on the same drive just moves the metadata, not the contents of the
file.
Total number of lines in the batch file : 7, if you include creating and
removing the temp directory.
If you want to have the folders at the top (File Explorer style) it only
takes a single extra line.
Regards,
Rudy Wieser
In addition to your latest reply to me up thread, this appears to
confirm that, unlike JJ, you did not accurately understand my stated
problem.

I did say it "will probably seem a rather obscure request" but...
Did you even take a look at the link I posted? For example this
important note about the central issue:
-------------------
"NOTE: The order you copy the mp3 into micro SD card will affect the
order mp3 played , which means play(1) function will play the first mp3
copied into micro SD card.'
--------------------
So here's my attempt at re-wording:
GIVEN the way that this module behaves, I was looking (as I have been
for a couple of years) for some way to ensure that files were physically
copied to an SD in the order they were displayed on the PC in File
Explorer. NOT describing some bizarre behaviour of File Explorer.
R.Wieser
2023-10-26 09:04:14 UTC
Permalink
Terry,
Post by Terry Pinnell
In addition to your latest reply to me up thread, this appears
to confirm that, unlike JJ, you did not accurately understand
my stated problem.
I'm sorry for your lack of attention, but I was not responding to you - but
instead to JJ and his mentioning of programs which could sort a directory.

As far as I'm concerned, your problem has been solved - regardless of if you
want to use the solution I offered or not.
Post by Terry Pinnell
I was looking (as I have been for a couple of years) for some way to
ensure that files were physically copied to an SD in the order they
were displayed on the PC in File Explorer.
And that was exactly what I offered you - together with some explanation to
how it works.

Regards,
Rudy Wieser
Terry Pinnell
2023-10-26 16:35:05 UTC
Permalink
Post by R.Wieser
Terry,
Post by Terry Pinnell
In addition to your latest reply to me up thread, this appears
to confirm that, unlike JJ, you did not accurately understand
my stated problem.
I'm sorry for your lack of attention, but I was not responding to you - but
instead to JJ and his mentioning of programs which could sort a directory.
As far as I'm concerned, your problem has been solved - regardless of if you
want to use the solution I offered or not.
Post by Terry Pinnell
I was looking (as I have been for a couple of years) for some way to
ensure that files were physically copied to an SD in the order they
were displayed on the PC in File Explorer.
And that was exactly what I offered you - together with some explanation to
how it works.
Regards,
Rudy Wieser
Well, in that case the penny has still not dropped for me! As per my
latest rather lengthy post, I still don't have a fully satisfactory
solution. But I'm getting closer, thanks to you and JJ. Plus my dislike
of unsolved puzzles ;-)

P.S. I'm sorry we got off to a bad start, with the console window
misunderstanding. And I have since seen a few references to it, as an
alternative to 'command prompt'.

Terry
JJ
2023-10-26 09:32:32 UTC
Permalink
Post by Terry Pinnell
Post by R.Wieser
JJ,
Post by JJ
For Windows, there are tools for sorting directory entries
in FAT drives.
A tool for sorting a directory ? For something that a small batch script
can do as wel ?
1) Move the to-be-sorted files to a temp directory (on the same drive*)
2) Create a sorted list of the files in the temp directory
3) Read the sorted list and move the files one-by-one back to the origional
directory
* moving on the same drive just moves the metadata, not the contents of the
file.
Total number of lines in the batch file : 7, if you include creating and
removing the temp directory.
If you want to have the folders at the top (File Explorer style) it only
takes a single extra line.
Regards,
Rudy Wieser
In addition to your latest reply to me up thread, this appears to
confirm that, unlike JJ, you did not accurately understand my stated
problem.
I did say it "will probably seem a rather obscure request" but...
Did you even take a look at the link I posted? For example this
-------------------
"NOTE: The order you copy the mp3 into micro SD card will affect the
order mp3 played , which means play(1) function will play the first mp3
copied into micro SD card.'
--------------------
GIVEN the way that this module behaves, I was looking (as I have been
for a couple of years) for some way to ensure that files were physically
copied to an SD in the order they were displayed on the PC in File
Explorer. NOT describing some bizarre behaviour of File Explorer.
Moreover... The sorting algorithm used by Explorer is different than the one
which is used by CMD (the program which interpret batch commands).

CMD uses binary sorting, while Explorer uses natural sorting.

It's not possible for a batch file to implement natural sort with mere 7
lines without using additional program.

Here's a DIR output with the `/on` switch (sort by name).

Volume in drive D is <censored>
Volume Serial Number is B934-3FE0

Directory of D:\0

11/16/2006 19:03 <DIR> .
03/31/2003 03:34 <DIR> ..
10/26/2023 16:18 0 file1
10/26/2023 16:18 0 file10
10/26/2023 16:18 0 file2
3 File(s) 0 bytes
2 Dir(s) 203,354,624 bytes free

Here's the DIR output without any switch (i.e. unsorted), and with no
`DIRCMD` environment variable. FYI, it's from a freshly created directory in
a FAT drive, where the files were created in this exact order: file10,
file2, file1. As you can see, it's sorted according to when they were
created. Just like what you're experiencing.

Volume in drive D is <censored>
Volume Serial Number is B934-3FE0

Directory of D:\0

11/16/2006 19:03 <DIR> .
03/31/2003 03:34 <DIR> ..
10/26/2023 16:18 0 file10
10/26/2023 16:18 0 file2
10/26/2023 16:18 0 file1
3 File(s) 0 bytes
2 Dir(s) 203,354,624 bytes free
R.Wieser
2023-10-26 09:50:31 UTC
Permalink
JJ,
Post by JJ
Moreover... The sorting algorithm used by Explorer is different than
the one which is used by CMD (the program which interpret batch
commands).
True. But it makes no difference for the what The OP provided as an example
to the involved filenames.
Post by JJ
It's not possible for a batch file to implement natural sort with mere
7 lines
Very likely true.
Post by JJ
without using additional program.
I have not tried it yet, so I can't tell you. I do know that I can switch
off the "natural" sorting - and have done so. I could imagine that some
registry editing by the batchfile (and reverting it afterwards) will do the
same.

But again, I took my que from his posted example. It will certainly work
for that.

But, if you do not like Batch to do the "heavy lifting" than you (and/or the
OP) could use one of the other script languages Windows offers, and which
has a lot more capabilities than Batch has.

In my case I used, for the exact same reason as the OP, VBScript.

Regards,
Rudy Wieser
Klaus Meinhard
2023-10-26 10:14:16 UTC
Permalink
Post by R.Wieser
But, if you do not like Batch to do the "heavy lifting" than you (and/or the
OP) could use one of the other script languages Windows offers, and which
has a lot more capabilities than Batch has.
In my case I used, for the exact same reason as the OP, VBScript.
Perhaps you folks should take a look at JP Software's Take Command, and
in this case especially at the free TCC/LE command prcessor replacement at

<https://jpsoft.com/all-downloads/all-downloads.html>

which is much more powerful but nearly 100% command.com compatible.

Copying files in name order would be a 1-liner batch, I suspect.
--
* Klaus Meinhard *
https://4dos.info/
R.Wieser
2023-10-26 12:53:30 UTC
Permalink
Klaus,
Post by Klaus Meinhard
Post by R.Wieser
In my case I used, for the exact same reason as the OP, VBScript.
Perhaps you folks should take a look at JP Software's Take Command, and
in this case especially at the free TCC/LE command prcessor replacement
If needed, I could write a Win32 program for it myself. Possibly a whole
GUI based program imitating File Explorer, or perhaps just a CLI one which
accepts a series of strings and uses the string compare File Explorer
usesfor sorting and outputs the result. Again to be used by a(ny) scripting
language. You know, it does just one thing, but it does it well (a linux
approach).

But now you say it, isn't it odd that File Explorer has one way of sorting,
the command line sorting one doesn't have seem to have a switch to emulate
it ?
Post by Klaus Meinhard
Copying files in name order would be a 1-liner batch, I suspect.
Programming languages do not get any better - but arguably worse - when they
stuff such tasks in single calls. Bloated software suffering from feature
creep.

But in that regard I'm still waiting for the "make awsome program" button in
such programming languages. A one-click, solves everything solution, which
can be used by the nitwittiest of nitwits. :-)

Regards,
Rudy Wieser
JJ
2023-10-27 00:12:52 UTC
Permalink
Post by R.Wieser
JJ,
Post by JJ
Moreover... The sorting algorithm used by Explorer is different than
the one which is used by CMD (the program which interpret batch
commands).
True. But it makes no difference for the what The OP provided as an example
to the involved filenames.
Post by JJ
It's not possible for a batch file to implement natural sort with mere
7 lines
Very likely true.
Post by JJ
without using additional program.
I have not tried it yet, so I can't tell you. I do know that I can switch
off the "natural" sorting - and have done so. I could imagine that some
registry editing by the batchfile (and reverting it afterwards) will do the
same.
But again, I took my que from his posted example. It will certainly work
for that.
But, if you do not like Batch to do the "heavy lifting" than you (and/or the
OP) could use one of the other script languages Windows offers, and which
has a lot more capabilities than Batch has.
In my case I used, for the exact same reason as the OP, VBScript.
Regards,
Rudy Wieser
I've no problem with batch file in general. But for OP's problem which use
memory chip based storage, the direct disk access would be ideal. Batch file
can't do direct disk access.
R.Wieser
2023-10-27 06:31:14 UTC
Permalink
JJ,
Post by JJ
I've no problem with batch file in general. But for OP's problem which
use memory chip based storage, the direct disk access would be ideal.
Batch file can't do direct disk access.
As I tried to explain, you don't need "direct disk access" for the job at
hand. Just copy (move) the files in the order you want them, and that's the
order they will be on the disk - regardless of it being spinning rust or
memory chip based.

Could you explain why you think you need such direct disk access for the
task at hand ? Seriously, 'cause I cannot imagine any reason for it.

Regards,
Rudy Wieser
Herbert Kleebauer
2023-10-27 07:28:21 UTC
Permalink
Post by R.Wieser
JJ,
Post by JJ
I've no problem with batch file in general. But for OP's problem which
use memory chip based storage, the direct disk access would be ideal.
Batch file can't do direct disk access.
As I tried to explain, you don't need "direct disk access" for the job at
hand. Just copy (move) the files in the order you want them, and that's the
order they will be on the disk - regardless of it being spinning rust or
memory chip based.
The order the files are copied is maybe not the same as in the
directory. That depends on the code which searches for a free
entry in the FAT table. To avoid a FAT with a large number of
deleted files, I suggested to first delete the directory and then
recreate it (or format the SD card if files are copied to the
root directory).
R.Wieser
2023-10-27 08:38:25 UTC
Permalink
Herbert,
Post by Herbert Kleebauer
The order the files are copied is maybe not the same as in the
directory. That depends on the code which searches for a free
entry in the FAT table.
I can't remember having ever had a problem with it, but understood.

Do you have any idea and/or example for which filesystems (OS versions ?)
that might be an issue ?

Regards,
Rudy Wieser
Herbert Kleebauer
2023-10-27 08:48:22 UTC
Permalink
Post by Terry Pinnell
Herbert,
Post by Herbert Kleebauer
The order the files are copied is maybe not the same as in the
directory. That depends on the code which searches for a free
entry in the FAT table.
I can't remember having ever had a problem with it, but understood.
Do you have any idea and/or example for which filesystems (OS versions ?)
that might be an issue ?
I think the OP uses Win10. And it isn't a big deal to
delete and recreate a directory. If it helps, ok. If not
then try the next thing. It's try and error, but if he
doesn't want to try, it's hard to solve the problem.
R.Wieser
2023-10-27 10:21:58 UTC
Permalink
Herbert,
Post by Herbert Kleebauer
Post by R.Wieser
Do you have any idea and/or example for which filesystems (OS versions ?)
that might be an issue ?
...
Post by Herbert Kleebauer
I think the OP uses Win10.
:-) My question was solely for myself. Perhaps the effect only occurs on
later versions of Windows (and I'm still in the clear).

By the way, I realized that the "code which searches for a free entry in the
FAT table" might even be as simple as an "look in the currently cached
cluster(s) first" approach.
Post by Herbert Kleebauer
but if he doesn't want to try, it's hard to solve the problem.
I gave him the same solution you did - though not on a single line - but he
chose to ignore it and instead wanted to bitch about how he understood a
phrase I used differently (and rather out of context). To which I bid him
goodbye and left him to his own devices.

Regards,
Rudy Wieser
JJ
2023-10-27 08:51:19 UTC
Permalink
Post by R.Wieser
As I tried to explain, you don't need "direct disk access" for the job at
hand. Just copy (move) the files in the order you want them, and that's the
order they will be on the disk - regardless of it being spinning rust or
memory chip based.
Could you explain why you think you need such direct disk access for the
task at hand ? Seriously, 'cause I cannot imagine any reason for it.
Regards,
Rudy Wieser
Hint: SD card
R.Wieser
2023-10-27 10:26:23 UTC
Permalink
JJ,
Post by JJ
Hint: SD card
Hint: USB sticks, SSD drives, MP3 players with integrated memory.

I still do not know how/why an SD card would be(have) different from
spinning rust or any of the above.

As far as I am aware, its the OS which is in control of where (the metadata
of) a file is stored, not the medium itself.

Regards,
Rudy Wieser
Terry Pinnell
2023-10-26 16:26:14 UTC
Permalink
Post by JJ
Post by Terry Pinnell
Post by R.Wieser
JJ,
Post by JJ
For Windows, there are tools for sorting directory entries
in FAT drives.
A tool for sorting a directory ? For something that a small batch script
can do as wel ?
1) Move the to-be-sorted files to a temp directory (on the same drive*)
2) Create a sorted list of the files in the temp directory
3) Read the sorted list and move the files one-by-one back to the origional
directory
* moving on the same drive just moves the metadata, not the contents of the
file.
Total number of lines in the batch file : 7, if you include creating and
removing the temp directory.
If you want to have the folders at the top (File Explorer style) it only
takes a single extra line.
Regards,
Rudy Wieser
In addition to your latest reply to me up thread, this appears to
confirm that, unlike JJ, you did not accurately understand my stated
problem.
I did say it "will probably seem a rather obscure request" but...
Did you even take a look at the link I posted? For example this
-------------------
"NOTE: The order you copy the mp3 into micro SD card will affect the
order mp3 played , which means play(1) function will play the first mp3
copied into micro SD card.'
--------------------
GIVEN the way that this module behaves, I was looking (as I have been
for a couple of years) for some way to ensure that files were physically
copied to an SD in the order they were displayed on the PC in File
Explorer. NOT describing some bizarre behaviour of File Explorer.
Moreover... The sorting algorithm used by Explorer is different than the one
which is used by CMD (the program which interpret batch commands).
CMD uses binary sorting, while Explorer uses natural sorting.
It's not possible for a batch file to implement natural sort with mere 7
lines without using additional program.
Here's a DIR output with the `/on` switch (sort by name).
Volume in drive D is <censored>
Volume Serial Number is B934-3FE0
Directory of D:\0
11/16/2006 19:03 <DIR> .
03/31/2003 03:34 <DIR> ..
10/26/2023 16:18 0 file1
10/26/2023 16:18 0 file10
10/26/2023 16:18 0 file2
3 File(s) 0 bytes
2 Dir(s) 203,354,624 bytes free
Here's the DIR output without any switch (i.e. unsorted), and with no
`DIRCMD` environment variable. FYI, it's from a freshly created directory in
a FAT drive, where the files were created in this exact order: file10,
file2, file1. As you can see, it's sorted according to when they were
created. Just like what you're experiencing.
Volume in drive D is <censored>
Volume Serial Number is B934-3FE0
Directory of D:\0
11/16/2006 19:03 <DIR> .
03/31/2003 03:34 <DIR> ..
10/26/2023 16:18 0 file10
10/26/2023 16:18 0 file2
10/26/2023 16:18 0 file1
3 File(s) 0 bytes
2 Dir(s) 203,354,624 bytes free
I successfully reproduced JJ's steps above in my context, using DIR in
the Command Prompt window. I'm much more comfortable with File Explorer
(FE) and most of what follows was done without using that window.

But the issue that prompted my post is that on transfer to the module
the playing order (using its accompanying software) does NOT then
reliably follow the order shown in FE. This is despite the order
apparently being Date Created. This was after tedious work with the
timestamp editing facility of Bulk Rename Utility (BRU) to get that
matched with Filename order.

So I spent most of today trying to discover why that happens. With some
limited new insights I think, but still working on it and I'd much
appreciate comments.

1. Retaining that Date created order in FE, I copied all 137 files from
source to micro SD card in USB drive L:. I used familiar FE operations
(select all, copy, paste); no batch, no script.

2. During this I got the warning shown. I always get such a message, so
I'll cover it here, although I don't think it's a relevant factor.
Loading Image...

I always get the message, and it's always the first file being copied
that triggers it. In this example you see it therefore gives an early
indication that the result will be unsatisfactory, as 0137 is the last
file, not the first. I responded with a Yes, and enabled the checkmark
box. If I instead perform the FE copy by first selecting the LAST file,
0137 in this case, and <Shift + Home> to select all, and then drag to
the empty destination, the message will show the first file, 0001.

3. I 'Safely removed...' the card from L: and placed it in the DFR Mini
MP3 Player module.

4. Then ran my Arduino sketch, to play all 137 files in sequence. It
failed, as usual, although on this occasion with only a few errors.

5. I then did another test; again sorted an identical 137 files to Date
created order and copied to card. The first sort of the card contents by
Date created showed 0001 as the first and 0137 last. But reversing the
sort by clicking the Date created column again gave this unexpected
result. And note this is in FE - the card is not yet in the module.
Loading Image...

6. My continued research today revealed a factor that's probably
familiar to those with more technical expertise but which was new to me.
A significant obstacle to resolving my problem is the lack of precision
in the Date created info shown in FE. It shows only to the minute. So a
series of entries that looks neatly continuous may not be. In BRU
precision is to seconds, but at milli or micro second speeds still not
an infallible tool in this context.
Loading Image...

WIP...

Terry
Herbert Kleebauer
2023-10-26 17:52:16 UTC
Permalink
Post by Terry Pinnell
Post by JJ
Moreover... The sorting algorithm used by Explorer is different than the one
which is used by CMD (the program which interpret batch commands).
CMD uses binary sorting, while Explorer uses natural sorting.
I successfully reproduced JJ's steps above in my context, using DIR in
the Command Prompt window. I'm much more comfortable with File Explorer
(FE) and most of what follows was done without using that window.
This problem doesn't exist with your names:

0001-.mp3
0002-.mp3
:

It would be only a problem if you use:
1-.mp3
:
9-.mp3
10-.mp3
Post by Terry Pinnell
But the issue that prompted my post is that on transfer to the module
the playing order (using its accompanying software) does NOT then
reliably follow the order shown in FE.
But it is copied in this order (if you select the first file for drag
and drop). If you don't believe it, copy one file after the other
or do it at the command prompt:

for /f %i in ('dir /b /on *.mp3') do copy %i d:\
Post by Terry Pinnell
1. Retaining that Date created order in FE, I copied all 137 files from
source to micro SD card in USB drive L:. I used familiar FE operations
(select all, copy, paste); no batch, no script.
Don't use copy and paste but drag and drop. But it is essential that you
use the first file for drag and drop.
Post by Terry Pinnell
2. During this I got the warning shown. I always get such a message, so
I'll cover it here, although I don't think it's a relevant factor.
https://www.dropbox.com/scl/fi/a31g01xszijbdpssr97rs/CopyingToUSB-Msg.jpg?rlkey=k5rkxnete0cuvg4lb4vb1scdc&raw=1
That's because you are copying from a NTFS to a FAT file system.
The alternate data stream (used for example to remember that the
file was copied from the internet an may be insecure) does not
exist on a FAT file system.

As I already said in my last post:

|| If you still get the wrong order, it is not because
|| of the copy process but the destination directory.
|| First erase the destination directory and then create
|| it again. Or if it is the root directory, format
|| the SD card before copying the files.
Terry Pinnell
2023-10-26 21:03:58 UTC
Permalink
Post by Herbert Kleebauer
Post by Terry Pinnell
Post by JJ
Moreover... The sorting algorithm used by Explorer is different than the one
which is used by CMD (the program which interpret batch commands).
CMD uses binary sorting, while Explorer uses natural sorting.
I successfully reproduced JJ's steps above in my context, using DIR in
the Command Prompt window. I'm much more comfortable with File Explorer
(FE) and most of what follows was done without using that window.
0001-.mp3
0002-.mp3
1-.mp3
9-.mp3
10-.mp3
Post by Terry Pinnell
But the issue that prompted my post is that on transfer to the module
the playing order (using its accompanying software) does NOT then
reliably follow the order shown in FE.
But it is copied in this order (if you select the first file for drag
and drop). If you don't believe it, copy one file after the other
for /f %i in ('dir /b /on *.mp3') do copy %i d:\
Post by Terry Pinnell
1. Retaining that Date created order in FE, I copied all 137 files from
source to micro SD card in USB drive L:. I used familiar FE operations
(select all, copy, paste); no batch, no script.
Don't use copy and paste but drag and drop. But it is essential that you
use the first file for drag and drop.
Post by Terry Pinnell
2. During this I got the warning shown. I always get such a message, so
I'll cover it here, although I don't think it's a relevant factor.
https://www.dropbox.com/scl/fi/a31g01xszijbdpssr97rs/CopyingToUSB-Msg.jpg?rlkey=k5rkxnete0cuvg4lb4vb1scdc&raw=1
That's because you are copying from a NTFS to a FAT file system.
The alternate data stream (used for example to remember that the
file was copied from the internet an may be insecure) does not
exist on a FAT file system.
|| If you still get the wrong order, it is not because
|| of the copy process but the destination directory.
|| First erase the destination directory and then create
|| it again. Or if it is the root directory, format
|| the SD card before copying the files.
Thanks Herbert, I plan to get back on the case tomorrow - it's been a
long day!

I am familiar with the points you make about the card file structure
after over a year working with this module.

You're right about dragging and also about doing so with first file
selected. I've lapsed on that recently and must be more disciplined
about it in future ;-) But just WHY those niceties are necessary remains
puzzling.

Most importantly, I'd appreciate any thoughts you/anyone may have on my
points #5 and #6 please?

Terry
Terry Pinnell
2023-10-27 11:38:02 UTC
Permalink
Post by Herbert Kleebauer
Post by Terry Pinnell
Post by JJ
Moreover... The sorting algorithm used by Explorer is different than the one
which is used by CMD (the program which interpret batch commands).
CMD uses binary sorting, while Explorer uses natural sorting.
I successfully reproduced JJ's steps above in my context, using DIR in
the Command Prompt window. I'm much more comfortable with File Explorer
(FE) and most of what follows was done without using that window.
0001-.mp3
0002-.mp3
1-.mp3
9-.mp3
10-.mp3
Post by Terry Pinnell
But the issue that prompted my post is that on transfer to the module
the playing order (using its accompanying software) does NOT then
reliably follow the order shown in FE.
But it is copied in this order (if you select the first file for drag
and drop). If you don't believe it, copy one file after the other
for /f %i in ('dir /b /on *.mp3') do copy %i d:\
Post by Terry Pinnell
1. Retaining that Date created order in FE, I copied all 137 files from
source to micro SD card in USB drive L:. I used familiar FE operations
(select all, copy, paste); no batch, no script.
Don't use copy and paste but drag and drop. But it is essential that you
use the first file for drag and drop.
Post by Terry Pinnell
2. During this I got the warning shown. I always get such a message, so
I'll cover it here, although I don't think it's a relevant factor.
https://www.dropbox.com/scl/fi/a31g01xszijbdpssr97rs/CopyingToUSB-Msg.jpg?rlkey=k5rkxnete0cuvg4lb4vb1scdc&raw=1
That's because you are copying from a NTFS to a FAT file system.
The alternate data stream (used for example to remember that the
file was copied from the internet an may be insecure) does not
exist on a FAT file system.
|| If you still get the wrong order, it is not because
|| of the copy process but the destination directory.
|| First erase the destination directory and then create
|| it again. Or if it is the root directory, format
|| the SD card before copying the files.
Thanks. From your original
for /f %i in ('dir /b /on *.mp3') do copy %i d:\
I expect I've made a mistake in my editing.

My source files are in the folder
C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1

And my destination is the USB drive L:\ containing the micro SD card.

So I ran this:
for /f %i in ('dir
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" /on
*.mp3') do copy %i L:\

which gave this result:

File Not Found

C:\Users\terry>copy Volume L:\
The system cannot find the file specified.
The system cannot find the file specified.
(repeated, presumably for all 137 files).
--------------------

I noted your aside earlier this morning ("...if he doesn't want to
try"):
I always not only delete the card's contents after every unsuccessful
exercise, but also Quick Format (3 seconds) or sometimes Full Format
(well over an hour).
Terry Pinnell
2023-10-27 12:00:14 UTC
Permalink
Post by Terry Pinnell
Post by Herbert Kleebauer
Post by Terry Pinnell
Post by JJ
Moreover... The sorting algorithm used by Explorer is different than the one
which is used by CMD (the program which interpret batch commands).
CMD uses binary sorting, while Explorer uses natural sorting.
I successfully reproduced JJ's steps above in my context, using DIR in
the Command Prompt window. I'm much more comfortable with File Explorer
(FE) and most of what follows was done without using that window.
0001-.mp3
0002-.mp3
1-.mp3
9-.mp3
10-.mp3
Post by Terry Pinnell
But the issue that prompted my post is that on transfer to the module
the playing order (using its accompanying software) does NOT then
reliably follow the order shown in FE.
But it is copied in this order (if you select the first file for drag
and drop). If you don't believe it, copy one file after the other
for /f %i in ('dir /b /on *.mp3') do copy %i d:\
Post by Terry Pinnell
1. Retaining that Date created order in FE, I copied all 137 files from
source to micro SD card in USB drive L:. I used familiar FE operations
(select all, copy, paste); no batch, no script.
Don't use copy and paste but drag and drop. But it is essential that you
use the first file for drag and drop.
Post by Terry Pinnell
2. During this I got the warning shown. I always get such a message, so
I'll cover it here, although I don't think it's a relevant factor.
https://www.dropbox.com/scl/fi/a31g01xszijbdpssr97rs/CopyingToUSB-Msg.jpg?rlkey=k5rkxnete0cuvg4lb4vb1scdc&raw=1
That's because you are copying from a NTFS to a FAT file system.
The alternate data stream (used for example to remember that the
file was copied from the internet an may be insecure) does not
exist on a FAT file system.
|| If you still get the wrong order, it is not because
|| of the copy process but the destination directory.
|| First erase the destination directory and then create
|| it again. Or if it is the root directory, format
|| the SD card before copying the files.
Thanks. From your original
for /f %i in ('dir /b /on *.mp3') do copy %i d:\
I expect I've made a mistake in my editing.
My source files are in the folder
C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1
And my destination is the USB drive L:\ containing the micro SD card.
for /f %i in ('dir
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" /on
*.mp3') do copy %i L:\
File Not Found
C:\Users\terry>copy Volume L:\
The system cannot find the file specified.
The system cannot find the file specified.
(repeated, presumably for all 137 files).
--------------------
I noted your aside earlier this morning ("...if he doesn't want to
I always not only delete the card's contents after every unsuccessful
exercise, but also Quick Format (3 seconds) or sometimes Full Format
(well over an hour).
I found at least one error in my edit, so I ran this:
for /f %i in ('dir /b /on
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" /on
*.mp3') do copy %i L:\

That gave this result:

C:\Users\terry>for /f %i in ('dir /b /on
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" /on
*.mp3') do copy %i L:\
File Not Found

C:\Users\terry>copy 0001-one550.mp3 L:\
The system cannot find the file specified.

C:\Users\terry>copy 0002-two.mp3 L:\
The system cannot find the file specified.

etc, for each of the 137 files.
Robert Roland
2023-10-27 12:30:49 UTC
Permalink
On Fri, 27 Oct 2023 12:38:02 +0100, Terry Pinnell
Post by Herbert Kleebauer
for /f %i in ('dir
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1" /on
*.mp3') do copy %i L:\
If you want it all in one line:

for /f %i in ('dir /on /b
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3
_files\FromL-1\*.mp3"') do copy
"C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1\%i" L:\

The /b matters. It tells the DIR command to output only the file
names.

If you can accept two lines, simply change the current directory (CD
command) to the directory that contains the MP3 files first. Then
Herbert's solution only needs the destination drive changed (this is
two lines):


cd "C:\Users\terry\Dropbox\Electronics\Arduino\SKETCHES\MY
SKETCHES\PROJECTS_Arduino\TalkingTemp Proj\_MP3 _files\FromL-1"
for /f %i in ('dir /b /on *.mp3') do copy "%i" L:\

The quotes around the path and %i are only required if the path
contains spaces, but it is good practice.

As mentioned earlier, if you want to put this into a batch file, the
percent signs must be doubled.
--
RoRo
Robert Roland
2023-10-26 22:17:26 UTC
Permalink
On Thu, 26 Oct 2023 17:26:14 +0100, Terry Pinnell
Post by Terry Pinnell
I'm much more comfortable with File Explorer
(FE) and most of what follows was done without using that window.
Explorer is unable to show the files in the order they appear in the
file system. It will always sort by someting. You can not choose to
sort by nothing. As a result, it is completely the wrong tool for this
job.

When you copy a file, the modified time stamp is also copied, even
when you copy to a FAT file system. So, the time stamps in the
destination directory will not reflect the time the file was copied,
but in stead the time when the source file was last modified.

Try Herbert's CMD solution or my PowerShell solution, and then put the
card into your MP3 module. Don't bother with Explorer.
--
RoRo
Al Rich
2023-11-26 20:04:08 UTC
Permalink
Post by Terry Pinnell
This will probably seem a rather obscure request. I need to find a way
to sequentially copy all the files from folder A to folder B. Trivial?
Unfortunately it seems not.
Folder B is an SD card (actually a micro-SD, various sizes). I don't
want to distract or bore with detail, but it's in a little module, 'DFR
Mini MP3 Player' from DF Robot in China.
https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
The module somehow 'indexes' the files in the order in which they are
transferred to the card. So that 002.mp3 must arrive in folder B after
001.mp3, and so on.
I'd always assumed this would be done automatically by Windows 10 File
Explorer. But to my dismay it clearly isn't so. Merely sorting folder A
into filename order
0001.mp3
0002.mp3
.
.
0123.mp3
and then using whatever combination of familiar steps in File Explorer I
try (wholesale copy/pasting, dragging, selecting from first or last
file, resetting attributes with other utilities, renaming, resorting,
etc) does not work consistently.
Even if I apparently get a winning combination, any subsequent change
(like adding 0124.mp3 after 0123.mp3) is not always reflected as
intuition would expect.
I'm considering resorting to using my Macro Express Pro application, to
simulate one-by-one dragging, but I know it would be painfully slow.
Right now, to proceed with my project, I have a mere 150 files, so I'll
tediously do it manually after (Fully, not Quick) formatting the card.
But I hope a batch file can cut the mustard please.
Or does anyone know of a property/attribute that can be changed on the
PC before copying, that will have the required 'sequential indexing'
effect?
Terry
If you are talking about copying files in a certain order so .mp3 players will play them in that order, then I wrote a VB program that will do that. It shuffles my mp3s and will write them in that order, so they play in that order. That way I don't have to use any Randomize function on mp3 players which I find don't always work correctly. The problem is, I wrote it for my PC, so it looks in my folder structure for the mp3s. I have mine basically stored... Music folder - Artist Folder - Track.mp3.
Loading...