# DOS/batch file question

**URL:** <https://boards.straightdope.com/t/dos-batch-file-question/753978>\
**Category:** Factual Questions\
**Created:** [May 5, 2016, 10:55am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978 "2016-05-05T10:55:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kobal2](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kobal2/32/20_2.png) [@Kobal2](https://boards.straightdope.com/u/Kobal2)\
**Post date:** [May 5, 2016, 10:55am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/1 "2016-05-05T10:55:06Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Ximenean](https://avatars.discourse-cdn.com/v4/letter/x/aca169/32.png) [@Ximenean](https://boards.straightdope.com/u/Ximenean)\
**Post date:** [May 5, 2016, 11:30am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/2 "2016-05-05T11:30:51Z")

</div>

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

```auto

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

```

so something like

```auto

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.

---

<div class="post-metadata">

**Author:** ![Doughbag](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Doughbag](https://boards.straightdope.com/u/Doughbag)\
**Post date:** [May 5, 2016, 2:07pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/3 "2016-05-05T14:07:25Z")

</div>

Mircosoft has the answer for your [HERE](https://support.microsoft.com/en-ie/kb/240268)

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

> [@](#):
>
> copy c:\Storage\DirectoryOLD\*.\* e:\Storage\DirectoryNEW\

This will copy all files and and directories/folders

> [@](#):
>
> xcopy c:\Storage\DirectoryOLD /s e:\Storage\DirectoryNEW\

\*\* underlined are your variables\*

---

<div class="post-metadata">

**Author:** ![Kobal2](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/kobal2/32/20_2.png) [@Kobal2](https://boards.straightdope.com/u/Kobal2)\
**Post date:** [May 6, 2016, 7:41am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/4 "2016-05-06T07:41:04Z")

</div>

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 ? 🙂

---

<div class="post-metadata">

**Author:** ![JWT\_Kottekoe](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@JWT\_Kottekoe](https://boards.straightdope.com/u/JWT_Kottekoe)\
**Post date:** [May 8, 2016, 1:53am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/5 "2016-05-08T01:53:22Z")

</div>

I’m disappointed. I thought this was going to be a question about [DOS/Batch](http://www.textfiles.com/bitsavers/pdf/dec/pdp11/dos-batch/DosBatchHandbook_v9_Apr74/00.pdf), the spanking new operating system for the PDP 11 computer, circa 1975. Those were the days.

---

<div class="post-metadata">

**Author:** ![dropzone](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dropzone/32/7515_2.png) [@dropzone](https://boards.straightdope.com/u/dropzone)\
**Post date:** [May 8, 2016, 2:05am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/6 "2016-05-08T02:05:49Z")

</div>

> [@Doughbag](#):
>
> Mircosoft has the answer for your [HERE](https://support.microsoft.com/en-ie/kb/240268)

[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.

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [May 8, 2016, 10:26am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/7 "2016-05-08T10:26:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [May 8, 2016, 6:44pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/8 "2016-05-08T18:44:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Doug\_K](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@Doug\_K](https://boards.straightdope.com/u/Doug_K)\
**Post date:** [May 8, 2016, 7:01pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/9 "2016-05-08T19:01:22Z")

</div>

> [@BigT](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [May 10, 2016, 9:24pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/10 "2016-05-10T21:24:58Z")

</div>

> [@Doug\_K](#):
>
> 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.)

---

<div class="post-metadata">

**Author:** ![Doug\_K](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@Doug\_K](https://boards.straightdope.com/u/Doug_K)\
**Post date:** [May 10, 2016, 11:55pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/11 "2016-05-10T23:55:30Z")

</div>

> [@ftg](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![BigT](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bigt/32/12044_2.png) [@BigT](https://boards.straightdope.com/u/BigT)\
**Post date:** [May 12, 2016, 8:47pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/12 "2016-05-12T20:47:29Z")

</div>

> [@Doug\_K](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)\
**Post date:** [May 12, 2016, 9:19pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/13 "2016-05-12T21:19:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hail\_Ants](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@Hail\_Ants](https://boards.straightdope.com/u/Hail_Ants)\
**Post date:** [May 12, 2016, 11:51pm UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/14 "2016-05-12T23:51:23Z")

</div>

> [@BigT](#):
>
> 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 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]

---

<div class="post-metadata">

**Author:** ![Senegoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senegoid/32/6606_2.png) [@Senegoid](https://boards.straightdope.com/u/Senegoid)\
**Post date:** [May 13, 2016, 12:28am UTC](https://boards.straightdope.com/t/dos-batch-file-question/753978/15 "2016-05-13T00:28:49Z")

</div>

> [@Hail\_Ants](#):
>
> \< . . . \> and going back to command line days:  
> [ul][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.
