android 遍历找文件
来源:互联网 发布:长城网络还原大师win7 编辑:程序博客网 时间:2024/05/21 16:23
1.在一个目录下找指定文件:videoename为文件名,如test.rmvb,subtitlePath=/mnt/sdb/adb1/ 查找结果:test.mkv等一系列的以test开头的文件
// add by cg 2013 07 25 for Subtitle
public boolean IsFindSubtitle(String videoename, String subtitlePath) {
String subtitlename = videoename.substring(0,
videoename.lastIndexOf("."));
File filePath = new File(subtitlePath);
if (filePath == null) {
return false;
}
// System.out.println("=====================IsFindSubtitle===================");
if (filePath.isDirectory()) {
File[] fileArray = filePath.listFiles();
if (fileArray != null) {
for (int i = 0; i < fileArray.length; i++) {
if (fileArray[i].getName().length() > subtitlename.length()) {
if (fileArray[i].getName()
.substring(0, subtitlename.length())
.equals(subtitlename)
&& (!fileArray[i].getName().equals(videoename))) {
// System.out.println(fileArray[i].getPath()+
// fileArray[i].getName());
Log.v("==========chenguo=====22222222222====",
"fileArray[" + i + "].getPath()"
+ fileArray[i].getPath()
+ " fileArray[" + i + "].getName()"
+ fileArray[i].getName());
}
}
}
}
}
return false;
}
// end by cg
2.遍历目录,直到找"Q-Agingtest.ts"文件为止
// 查找testvideo.rmvb
private void Traversaltestvideo(File f) {
int flage = 0;
if (f != null && false == testvideoinfo[1].equals("Q-Agingtest.ts")) {// f为null或找到testvideo.rmvb退出递归
if (f.isDirectory()) {
File[] fileArray = f.listFiles();
if (fileArray != null) {
for (int i = 0; i < fileArray.length; i++) {
// 递归调用
// System.out.println(fileArray[i].getName());
Traversaltestvideo(fileArray[i]);
}
}
}
else {
if (1 != flage) {
String testvideo = "Q-Agingtest.ts";
if (f.getName().equals(testvideo)) {
flage = 1;
testvideoinfo[0] = f.getPath();
testvideoinfo[1] = f.getName();
// Log.v("====testvideoinfo===","testvideoinfo testvideoinfo ok "
// + testvideoinfo[0]);
System.out.println(f.getPath());
}
}
}
}
}
测试:在/mnt/目录开始遍历所有目录及文件,直到找到"Q-Agingtest.ts"或全部遍历完为止
void test()
{
String[] testvideoinfo = new String[2];
String fileName = "/mnt" + File.separator;
File f = new File(fileName);
// 初始化uxb_numinfo 0
for (int i = 0; i < 2; i++)
testvideoinfo[i] = "0";
Traversaltestvideo(f);
}
// add by cg 2013 07 25 for Subtitle
public boolean IsFindSubtitle(String videoename, String subtitlePath) {
String subtitlename = videoename.substring(0,
videoename.lastIndexOf("."));
File filePath = new File(subtitlePath);
if (filePath == null) {
return false;
}
// System.out.println("=====================IsFindSubtitle===================");
if (filePath.isDirectory()) {
File[] fileArray = filePath.listFiles();
if (fileArray != null) {
for (int i = 0; i < fileArray.length; i++) {
if (fileArray[i].getName().length() > subtitlename.length()) {
if (fileArray[i].getName()
.substring(0, subtitlename.length())
.equals(subtitlename)
&& (!fileArray[i].getName().equals(videoename))) {
// System.out.println(fileArray[i].getPath()+
// fileArray[i].getName());
Log.v("==========chenguo=====22222222222====",
"fileArray[" + i + "].getPath()"
+ fileArray[i].getPath()
+ " fileArray[" + i + "].getName()"
+ fileArray[i].getName());
}
}
}
}
}
return false;
}
// end by cg
2.遍历目录,直到找"Q-Agingtest.ts"文件为止
// 查找testvideo.rmvb
private void Traversaltestvideo(File f) {
int flage = 0;
if (f != null && false == testvideoinfo[1].equals("Q-Agingtest.ts")) {// f为null或找到testvideo.rmvb退出递归
if (f.isDirectory()) {
File[] fileArray = f.listFiles();
if (fileArray != null) {
for (int i = 0; i < fileArray.length; i++) {
// 递归调用
// System.out.println(fileArray[i].getName());
Traversaltestvideo(fileArray[i]);
}
}
}
else {
if (1 != flage) {
String testvideo = "Q-Agingtest.ts";
if (f.getName().equals(testvideo)) {
flage = 1;
testvideoinfo[0] = f.getPath();
testvideoinfo[1] = f.getName();
// Log.v("====testvideoinfo===","testvideoinfo testvideoinfo ok "
// + testvideoinfo[0]);
System.out.println(f.getPath());
}
}
}
}
}
测试:在/mnt/目录开始遍历所有目录及文件,直到找到"Q-Agingtest.ts"或全部遍历完为止
void test()
{
String[] testvideoinfo = new String[2];
String fileName = "/mnt" + File.separator;
File f = new File(fileName);
// 初始化uxb_numinfo 0
for (int i = 0; i < 2; i++)
testvideoinfo[i] = "0";
Traversaltestvideo(f);
}
- android 遍历找文件
- Android文件递归遍历
- android,在文件中找一个String
- android 使用递归遍历文件
- android遍历获取sdcard文件
- Android 根据文件Uri找文件路径 和根据路径找文件Uri
- android直接找一个文件,部分编译等实用
- android直接找一个文件,部分编译等实用
- android导入项目找不R文件,解决方法
- 关于如何在Android studio里找.db文件
- android快速遍历目录及查找文件
- Android.mk遍历子目录所有文件
- Android遍历获取指定目录的文件
- Android.mk遍历子目录所有文件
- android 遍历assert文件夹下的文件
- cocos2d-x配置Android.mk遍历文件
- Android JAVA文件遍历小妙招
- Android遍历手机内所有文件
- js根据数值动态生成文本框,Javascript
- excel文件中批量生成insert语句
- 使用免费的云服务 AWS EC2
- IOS4直接获取摄像头数据
- 第一篇CSDN博客
- android 遍历找文件
- Linux下的硬件驱动——USB设备(下)(驱动开发部分)
- hdu2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (多重背包)
- 机器学习中的相似性度量
- 触发器中判断 插入 or 更新 or 删除
- 构建和运行
- spring 监听器
- 强制垃圾回收
- Truncate Table user