0
我的代碼用於重命名SD卡上的文件夾中的文件,但是,它不會重命名同一文件夾中存在的子文件夾中的文件。如何在android中獲取子目錄?
這裏是我的方法,我加入這行 -
ExplorerDBOperation(listFile[i]);
,但我得到的錯誤是 - 「的方法ExplorerDBOperation(文件)是未定義的類型Hide.ExplorerDBOperation」我怎麼叫我的方法再次?這是在的AsyncTask
@Override
protected Boolean doInBackground(Void... params) {
File listFile[] = myDirectory.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
ExplorerDBOperation(listFile[i]);
} else {
String fPath = listFile[i].getPath();
for (String ext : TARGET_EXTENSIONS) {
fPath = fPath.replace("." + ext,
"a6d5dx" + ext);
}
listFile[i].renameTo(new File(fPath));
}
}
}
return true;
}
全碼
// getting SDcard root path
File myDirectory = new File(Environment.getExternalStorageDirectory()
+ "/SecuDrive/");
public static final String[] TARGET_EXTENSIONS = { "exe", "apk", "tar", "img", "iso" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hide);
// at the end of oncreate
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new ExplorerDBOperation().execute();
}
}, 300);
}
class ExplorerDBOperation extends AsyncTask<Void, Boolean, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(Hide.this, "Please wait",
"Processing..");
}
@Override
protected Boolean doInBackground(Void... params) {
File listFile[] = myDirectory.listFiles();
if (listFile != null) {
for (int i = 0; i < listFile.length; i++) {
if (listFile[i].isDirectory()) {
ExplorerDBOperation(listFile[i]);
} else {
String fPath = listFile[i].getPath();
for (String ext : TARGET_EXTENSIONS) {
fPath = fPath.replace("." + ext,
"a6d5dx" + ext);
}
listFile[i].renameTo(new File(fPath));
}
}
}
return true;
}
renameInDir(listfile中[1]);只是這條線? – abbie
@abbie aha,請注意,您需要在異步任務中添加此方法 –