获取当前目录getcwd,设置工作目录chdir,获取目录信息
#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,获取目录信息的更多相关文章
- python 获取当前目录,上级目录,上上级目录
import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...
- Python学习笔记_获取当前目录和上级目录
实验目标:获取当前目录和上级目录 系统环境: 1.OS:Win10 64位 2.Pythoh 3.7 3.实验路径:C:\Work\Python\MergeExcel 代码参考: # -*- codi ...
- Python基础-获取当前目录,上级目录,上上级目录
import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...
- os:获取当前目录路径,上级目录路径,上上级目录路径
import os '''***获取当前目录***''' print(os.getcwd()) print(os.path.abspath(os.path.dirname(__file__))) '' ...
- bat 获取当前目录的父目录
bat 获取当前目录的父目录 @echo off echo batchfile=%0 echo full=%~f0 setlocal for %%d in (%~dp0.) do set Direct ...
- python笔记(一)获取当前目录路径和文件
一.获取当前路径 1.使用sys.argv[0] import sys print sys.argv[0]#输出#本地路径 2.os模块 import os print os.getcwd() #获取 ...
- Linux Kernel中获取当前目录方法(undone)
目录 . 引言 . 基于进程内存镜像信息struct mm_struct获取struct path调用d_path()获取当前进程的"绝对路径" . 基于文件描述符(fd).tas ...
- 警惕System.Environment.CurrentDirectory 获取当前目录
最近工作中,要做个客户端提醒的小工具:winform程序自然少不了要读取和应用程序同一个目录的配置文件(不是exe.config文件): 要读取当前应用程序所在目录我立马想到了System.Envir ...
- R语言中获取当前目录
# 获取当前工作目录 getwd() # 设置工作目录 setwd()
随机推荐
- Python3基础 hasattr 测试类是否有指定的类属性
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Linux系统编程--文件描述符的复制dup()和dup2()【转】
本文转载自:http://blog.csdn.net/tennysonsky/article/details/45870459 dup() 和 dup2() 是两个非常有用的系统调用,都是用来复制一个 ...
- 分布式系统一致性协议--Paxos算法
Paxos: Paxos算法背景介绍: Paxos算法是分布式技术大师Lamport提出的,主要目的是通过这个算法,让参与分布式处理的每个参与者逐步达成一致意见.用好理解的方式来说,就是在一个选举过程 ...
- HDU 2841 Visible Trees(容斥)题解
题意:有一块(1,1)到(m,n)的地,从(0,0)看能看到几块(如果两块地到看的地方三点一线,后面的地都看不到). 思路:一开始是想不到容斥...后来发现被遮住的地都有一个特点,若(a,b)有gcd ...
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件的作用
转载自:http://blog.csdn.net/u013968345/article/details/21262033 /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登 ...
- C++ 清空队列(queue)的几种方法
C++中的queue自身是不支持clear操作的,但是双端队列deque是支持clear操作的. 方法一 直接用空的队列对象赋值 queue<int> q1; // process // ...
- K条最短路径算法(KSP, k-shortest pathes):Yen's Algorithm
参考: K最短路径算法之Yen's Algorithm Yen's algorithm 基于网络流量的SDN最短路径转发应用 K条最短路径算法:Yen's Algorithm 算法背景 K 最短路径问 ...
- 《重构网络:SDN架构与实现》Chapter7 SDN与网络虚拟化 随笔
参考: <重构网络:SDN架构与实现>,作者:杨泽卫.李呈. Chapter7 SDN与网络虚拟化 结构 7.1 网络虚拟化 7.1.1 为什么需要网络虚拟化技术 7.1.2 网络虚拟化 ...
- UVa 1374 快速幂计算(dfs+IDA*)
https://vjudge.net/problem/UVA-1374 题意:给出n,计算最少需要几次能让x成为x^n(x和已经生成的数相乘或相除). 思路:IDA*算法. 如果当前数组中最大的数乘以 ...
- 生信软件的好帮手-bioconda--转载
http://mp.weixin.qq.com/s/nK1Kkf9lfZStoX25Y7SzHQ 这篇文章主要适用于Linux平台,当然MacOS也行,不过它有更好安装方法. 此外网上也会许多更好的关 ...