获取当前目录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()
随机推荐
- web应用下的安全问题以及tomcat/nginx对应解决方法(持续更新、亲测可解决问题)
最近一券商那边扫描反馈了下面几个非业务型安全漏洞,要求解决,如下: XSS 自己写个脚本response的时候对特殊字符进行了处理,或者网上搜下一堆(不要忘了回车.换行). HTML form wit ...
- Django 将数据库查出的 QuerySet 对象转换为 json 字符串
通过Django查询出MySQL数据库的数据,并将查询出的QuerySet 对象转化成 json 字符串. 写这个例子的作用主要是用来为手机端提供接口用,记录一下,以后 说不准 肯定能用到! ---- ...
- 20145330 《网络对抗》 Web基础
20145330 <网络对抗> Web基础 1.实践内容 (1)Web前端HTML (2)Web前端javascipt (3)Web后端:MySQL基础:正常安装.启动MySQL,建库.创 ...
- RS(纠删码)技术浅析及Python实现
前言 在Ceph和RAID存储领域,RS纠删码扮演着重要的角色,纠删码是经典的时间换空间的案例,通过更多的CPU计算,降低低频存储数据的存储空间占用. 纠删码原理 纠删码基于范德蒙德矩阵实现,核心公式 ...
- cogs 1962. [HAOI2015]树上染色
★★☆ 输入文件:haoi2015_t1.in 输出文件:haoi2015_t1.out 简单对比 时间限制:1 s 内存限制:256 MB [题目描述] 有一棵点数为N的树,树边有边 ...
- 多线程中的信号机制--signwait()函数【转】
本文转载自:http://blog.csdn.net/yusiguyuan/article/details/14237277 在Linux的多线程中使用信号机制,与在进程中使用信号机制有着根本的区别, ...
- SPOJ - POLYNOM Polynomial(数论乱搞)题解
题意 :给你n个数,问你是否存在一个多项式(最多三次方)满足f(i)= xi. 思路:讲一个神奇的思路: x3 - (x - 1)3 = 3x2 - 3x + 1 x2 - (x - 1)2 = 2x ...
- HDU 1285 确定比赛名次(拓扑排序)题解
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...
- The equation (扩展欧几里得)题解
There is an equation ax + by + c = 0. Given a,b,c,x1,x2,y1,y2 you must determine, how many integer r ...
- Leetcode ——Partition Equal Subset Sum
Question Given a non-empty array containing only positive integers, find if the array can be partiti ...