About

File in DOS.

Management

Create

See What are Redirection Operators in Dos with example and how-to?

File Attribute (name, path, …)

in a for loop:

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

Change Attribute

Dos - Attrib Command (File Attributes)

IF Exist

See if exist statement

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