#include <unistd.h>
#include <stdio.h>
#include <limits.h> int main(int argc, char* argv[])
{
char buf[PATH_MAX]; getcwd(buf, PATH_MAX-); printf("the current path is :%s\n", buf); return ;
}

设置工作目录:

#include <unistd.h>

int chdir(const char *path);
int fchdir(int fd);

chdir() changes the current working directory of the calling process to the directory specified in path.

fchdir() is identical to chdir(); the only difference is that the directory is given as an open file descriptor.

-----------------------------------

只要对目录有读写权限,就可获取目录信息。

打开目录:opendir

读取目录: readdir

关闭目录:closedir

DIR *opendir(const char *name);
DIR *fdopendir(int fd);

struct dirent *readdir(DIR *dirp);

int closedir(DIR *dirp);

#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h> int my_readdir(const char* path)
{
DIR *dirp;
struct dirent *ptr; if ( (dirp=opendir(path)) == NULL)
{
return -;
} while( (ptr=readdir(dirp)) != NULL)
{
printf("file name is:%s\n", ptr->d_name);
} return ;
} int main(int argc, char* argv[])
{ if (argc < )
{
exit();
} if(my_readdir(argv[]) < )
{
exit();
} return ;
}

获取当前目录getcwd,设置工作目录chdir,获取目录信息的更多相关文章

  1. python 获取当前目录,上级目录,上上级目录

    import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...

  2. Python学习笔记_获取当前目录和上级目录

    实验目标:获取当前目录和上级目录 系统环境: 1.OS:Win10 64位 2.Pythoh 3.7 3.实验路径:C:\Work\Python\MergeExcel 代码参考: # -*- codi ...

  3. Python基础-获取当前目录,上级目录,上上级目录

    import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...

  4. os:获取当前目录路径,上级目录路径,上上级目录路径

    import os '''***获取当前目录***''' print(os.getcwd()) print(os.path.abspath(os.path.dirname(__file__))) '' ...

  5. bat 获取当前目录的父目录

    bat 获取当前目录的父目录 @echo off echo batchfile=%0 echo full=%~f0 setlocal for %%d in (%~dp0.) do set Direct ...

  6. python笔记(一)获取当前目录路径和文件

    一.获取当前路径 1.使用sys.argv[0] import sys print sys.argv[0]#输出#本地路径 2.os模块 import os print os.getcwd() #获取 ...

  7. Linux Kernel中获取当前目录方法(undone)

    目录 . 引言 . 基于进程内存镜像信息struct mm_struct获取struct path调用d_path()获取当前进程的"绝对路径" . 基于文件描述符(fd).tas ...

  8. 警惕System.Environment.CurrentDirectory 获取当前目录

    最近工作中,要做个客户端提醒的小工具:winform程序自然少不了要读取和应用程序同一个目录的配置文件(不是exe.config文件): 要读取当前应用程序所在目录我立马想到了System.Envir ...

  9. R语言中获取当前目录

    # 获取当前工作目录 getwd() # 设置工作目录 setwd()

随机推荐

  1. vc++之stdafx.h

    关于stdafx.h的解释,其实蛮多的,在vs中,既然创建c++工程的时候,默认会给生成main.cpp,并且自动包含了stdafx.h,而且stdafx.h不是c++标准的一部分,那么个人认为,理解 ...

  2. Win10 Ubuntu 双系统 卸载 Ubuntu

    Win10 Ubuntu 双系统 卸载 Ubuntu 其实卸载 Ubuntu 系统很简单,进 win10 系统之后,磁盘管理,格式化 Ubuntu 的磁盘就可以了. 但是最费劲的是什么呢? 就是格式化 ...

  3. uboot 网络驱动模型

    原文:https://blog.csdn.net/zhouxinlin2009/article/details/45390065 UBOOT的PHYCHIP配置 PHYCHIP的配置位于 includ ...

  4. 在Windows下搭建Android开发环境及遇到的问题

    转载1:http://www.cnblogs.com/xdp-gacl/p/4322165.html 转载2:http://www.cnblogs.com/zoupeiyang/p/4034517.h ...

  5. HDU 1823 Luck and Love (二维线段树&区间最值)题解

    思路: 树套树,先维护x树,再维护y树,多练练应该就能懂了 代码: #include<cstdio> #include<cmath> #include<cstring&g ...

  6. springmvc-自定义消息转换器

    最近的项目没有用到这个,先把自己自学跑通的例子先帖出来,供自己以后参考吧! 如有不对地方望指出! 一.自定义类实现AbstractHttpMessageConverter package com.dz ...

  7. js函数事件对象

    每个函数都有4个默认对象 arguments 保存着实际传入的参数,集合列表 return 有两个功能,打断函数和返回函数值 this 谁调用的函数,this就是谁 event 事件对象 事件 box ...

  8. DataSet 动态添加列

    public DataSet GetNewId(List<string> IdArr) { DataSet ds = new DataSet(); DataTable newtb = ne ...

  9. python 元组列表转为字典

    #create a list l = [(), (), (), (), (), ()] d = {} for a, b in l: d.setdefault(a, []).append(b) prin ...

  10. Python day19 模块介绍3(sys,json,pickle,shelve,xml)

    1.sys模块 import sys sys.path()#打印系统path sys.version()#解释程序版本信息 sys.platform()#系统平台 sys.exit(0)#退出程序 c ...