Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I stumbled on question 217394 which explains how to copy files sorted alphabetically into one single file. Trying to implement the command myself rendered the following error message: The system cannot find the file specified.
The command I am trying to run is here:

for /f %i in ('dir /a-d /o-n /b O:\OrdersExport\Order*.txt') do @type %i >> C:\Users\Admin\Documents\OrderImport.txt

The error does not appear if I browsed to the folder in question first:

C:\>O:
C:\>cd OrdersImport

I simply want one line to copy from destination to that single file.

By the way, if it matters, O: is a mapped folder over network

share|improve this question

1 Answer 1

The dir command list the filenames only. So %i variable is filled with relative paths. If the command is not run from the directory in question use %~fi to expand the relative path to absolute path.

for /f "tokens=*" %i in ('dir /a-d /o-n /b "O:\OrdersExport\Order*.txt"') do (
    @type "%~fi" >> "C:\Users\Admin\Documents\OrderImport.txt"
)
  • tokens=* deals with spaces in filenames, so %i is always whole line of the dir output.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.