PTN
PTN

Reputation: 1692

Delete a file in a specified directory C

I believe there is a function in stdio.h called remove() that removes a file by passing in the file name like remove("foo.txt"). However, if I want to remove a file in a specified path, how do I do that?

Upvotes: 1

Views: 80

Answers (3)

Liyuan Liu
Liyuan Liu

Reputation: 172

first check your program user rights allow to remove this file

second get full path like: remove("/home/test/foo.txt")

Upvotes: 1

ameyCU
ameyCU

Reputation: 16607

You can do this -

remove("drive\\folder\\foo.txt"):

Remember you have to put \\ between path. \ won't work compiler will show error.

Upvotes: 1

Barmar
Barmar

Reputation: 780861

Use the absolute path:

remove("/path/to/foo.txt");

Upvotes: 3

Related Questions