#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. Linux 虚拟机安装vmware tools

    Linux Vmware tools安装步骤 1 在 vSphere Client 清单中,右键单击虚拟机,然后选择电源 > 开启.   2 单击控制台选项卡以确定客户机操作系统启动成功,并在需 ...

  2. 编译安装 http

    1. 安装 apr http服务依赖 apr和apr-util ,安装 http 前需先安装这两个程序 apr 简介:http://www.cnblogs.com/Alight/p/3997777.h ...

  3. PHP进程及进程间通信

    一.引言 进程是一个具有独立功能的程序关于某个数据集合的一次运行活动.换句话说就是,在系统调度多个cpu的时候,一个程序的基本单元.进程对于大多数的语言都不是一个陌生的概念,作为"世界上最好 ...

  4. 04: 打开tornado源码剖析处理过程

    目录:Tornado其他篇 01: tornado基础篇 02: tornado进阶篇 03: 自定义异步非阻塞tornado框架 04: 打开tornado源码剖析处理过程 目录: 1.1 torn ...

  5. 20145212罗天晨 注入shellcode实验及Retuen-to-libc实验

    注入shellcode实验 实验步骤 一.准备一段shellcode 二.设置环境 Bof攻击防御技术 1.从防止注入的角度来看:在编译时,编译器在每次函数调用前后都加入一定的代码,用来设置和检测堆栈 ...

  6. DD-WRT自定义脚本更新花生壳DDNS

    N年以前买了一个tp-link 841n v7,一直用的还算可以吧,除了不定期重启路由器,不然网速慢的龟爬啊!这也是TP原厂固件的通病,于是刷了DD-WRT,话说DD确实很爽,除了功能强大之外,而且很 ...

  7. SpringBoot中的Quartz应用

    Spring自带定时器任务: code: import org.springframework.beans.factory.annotation.Configurable; import org.sp ...

  8. poj 8469 特殊密码锁

    a:特殊密码锁 总时间限制: 1000ms 内存限制: 1024kB 描述 有一种特殊的二进制密码锁,由n个相连的按钮组成(n<30),按钮有凹/凸两种状态,用手按按钮会改变其状态. 然而让人头 ...

  9. async 和 await的前世今生 (转载)

    async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们编程埋下了一些隐 ...

  10. DB中字段为null,为空,为空字符串,为空格要怎么过滤取出有效值

      比如要求取出微信绑定的,没有解绑的 未绑定,指定字段为null 绑定的,指定字段为某个字符串 解绑的,有的客户用的是更新指定字段为1,有的客户更新指定字段为‘1’ 脏数据的存在,比如该字段为空字符 ...