DOS - File

About

File in DOS.

Management

Create

File Attribute (name, path, …)

in a for loop:

  • the file name without extension.
%%~nf
  • Fully Qualified Path Name
%~fI

Change Attribute

IF Exist

Delete

del myFile.txt

See:

Rename

rename myFile.txt myRenameFile.txt

Display the content

TYPE filename

type will display the contents of a text file or files.

Re-assigning file ownership

takeown /?

Concatenate two files

By using the type command and the redirections operators, you can concatenate files.

Example that add the content of file1.txt in file2.txt

type file1.txt >> file2.txt

Compare

See fc Compares two files or sets of files, and displays the differences between them.

File Association

How to create:

  • Example with Python:
set PATHEXT=%PATHEXT%;.PY
assoc .py=Python.File
ftype Python.File=c:\Python27\python.exe "%1" %*

where:

Copy

Directory

Recursively with xcopy (a better version of copy)

xcopy C:\source D:\target\path /s /e /h /y

where:

  • s copies all sub directory (not the empty one)
  • e copies also the empty directory
  • h copies also hidden files
  • y don't prompt to override

See for details over the options


Powered by ComboStrap