DOS/batch file question

I’d like to move a large number of files stored in a number of directories up one level.
That is to say I have fileA in c:\Storage\DirectoryA and fileB in c:\Storage\DirectoryB (and so on) ; and would like to automagically move all of the files to c:\Storage.
Obviously I could do it all by cut/paste, but a) it’d be a pain in my neck and b) I figure there must be a way to do that via DOS command line.

Little help ?

The general way of iterating over directories in a cmd shell is:


for /d %a in (<dirs>) do <whatever>

so something like


for /d %%a in (c:\Storage\Directory?) do (
  copy %%a\*.* c:\Storage\  // you could use move, but I'd copy first and check that it's OK
)

(you need double percent signs if running from a cmd file.)

You might also be able to do it with for /f if that can be made to recursively look through subdirectories, but I don’t know if it can.

Mircosoft has the answer for your HERE

This will copy all files in that directory, but won’t copy folders, also the destination folder has to be there as well

This will copy all files and and directories/folders

** underlined are your variables*

Thanks a bunch, guys ! All done and neat. Now to reorganize them the right way. Don’t you just hate working with someone else’s silly illogical probably insane file sorting/naming scheme ? :slight_smile:

I’m disappointed. I thought this was going to be a question about DOS/Batch, the spanking new operating system for the PDP 11 computer, circa 1975. Those were the days.

[Pointless Anecdote] For a couple years in the late-mid-90s I went to a JC for a Microcomputer Support certificate. All that stood in my way was an introductory MS-DOS class. I asked the department head, “Ma’am, if you have any openings I could TEACH that class. May I substitute a class with a future?”

I didn’t complete the certificate program.

Just a general point, but shuffling files within a directory structure like this has disaster written all over it - I speak from experience! It’s generally a better idea to copy the files to a new directory, then rename the directories. And only after you’ve checked everything delete the old files.

This actually isn’t too hard in the GUI, in my opinion. It is copy and paste, but it’s a single operation. Open the directory. Do a search for .. Right click and select all, then right click cut. Then hit back to get back to the folder without search, and click paste. Delete any folders.

Well, that is, unless there were files like C:\A\B\D that you wanted to move to C:\A\D. Then command line is probably better.

NEVER do cut and paste with important data. Do copy and paste instead. If the paste fails you’re screwed.

Also Control-a is much faster than right-click/select all and control-c is much faster than right-click/copy

But ^C is right next to ^V and I’ve had horrid things happen when the wrong one gets hit. The right menu is slower but safer. (Ditto the insert/delete keys shouldn’t be next to each other either for safety reasons.)

What horrid things? Worst case you just have to go back and copy again.

Pressing Ctrl-V when you meant Ctrl-C will replace everything you highlighted with what was previously on the clipboard.

Though this is less of a big deal with Ctrl-Z.

I’ve just spotted that Ximenean’s code has an error in it. You should use * instead of . as the latter mandates an extension.

I do this all the time, do a (previous) paste when I meant to do a new copy. Fortunately CTRL+Z always works as an undo (in Windows anyway, don’t know about Macs).

FWIW the story I heard as to why those keys were chosen:
[ul]
[li]CTRL+X = **Cut **because an X looks like a pair of scissors[/li][li]CTRL+C = **Copy **because copy begins with C[/li][li]CTRL+V = **Paste **because, well, because it’s right next to X and C (probably why CTRL+Z was also chosen)[/li]
and I assume:
[li]CTRL+A = Select All because all begins with A[/li]
and going back to command line days:
[li]CTRL+S = pause (or Stop)[/li][li]CTRL+Q = continue because you can hold CTRL and alternately press S and Q easily with your index and middle fingers[/li][/ul]

Ctrl-S (X-OFF) and Ctrl-Q (X-ON) go back way farther than that. Once upon a time, before ASCII terminals were ever connected to computers, you had mechanical Teletypes connected to modems, connected to phone lines, connected to a modem at the other end, connected to a Teletype. No computers in the middle. Those were the days when communication by telegraph had progressed beyond using simple clicks and Morse code.

Many of the codes we now call “Control Characters” were, in those days, really used as control characters. Control-D, for example, literally meant “End of Conversation” and caused the modem to hang up. Control-G rang the bell on the teletype. Control-M was literally Carriage Return, and Control-J was literally Line Feed. A bunch of other control characters has various physical, mechanical actions. (Tab, Vertical Tab, Form-Feed, etc.)

If the receiving unit could not keep pace with the sending unit, it could send X-OFF (Ctrl-S) to tell the sending unit to pause, then send X-ON (Ctrl-Q) to tell the sending unit to resume. Hopefully, most sending units were smart enough to comply.

Attaching Teletype terminals to interactive computers came later.