简体   繁体   中英

how to simulate the dos “CD..” in a small c shell for linux

this is for a small project of mine, I'm trying to set the current process working directory to the One directory up as if my current directory is ..\\downloads\\movies i'd like code to set the directory to ..\\downloads

I know this is possible by getting the current working directory path and extracting the directory path i need from it and then do a chdir(), however this code needs to be as efficient and light as possible, and i find the above method kinda cumbersome.

Thanks in advance falks.

How simple and efficient are you looking to be? Something like

if (chdir("..") < 0)
{
    perror("chdir");
    exit(1);
}

U can try doing something like this

chdir("..");

Santi! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM