android - 在 Unity 3d Android 平台中将图像从一个文件夹复制到另一个文件夹
问题描述
我正在寻找这个问题很多天。我正在开发 Unity 3d Android 项目。是否可以在按下按钮时选择图像,然后在按下另一个按钮时将该图像复制到另一个文件夹?我见过太多的插件,其中大部分是 UnityEditor(PC 平台)和 android 平台都不起作用。请回复。
解决方案
这是我的代码
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class FileC : MonoBehaviour
{
public void save()
{
string fileName = "a.png";
string sourcePath = @"/mnt/sdcard/Test1";
string targetPath = @"/mnt/sdcard/Test2";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(sourcePath))
{
System.IO.Directory.CreateDirectory(sourcePath);
}
// To copy a file to another location and
// overwrite the destination file if it already exists.
System.IO.File.Copy(sourceFile, destFile, true);
// To copy all the files in one directory to another directory.
// Get the files in the source folder. (To recursively iterate through
// all subfolders under the current directory, see
// "How to: Iterate Through a Directory Tree.")
// Note: Check for target path was performed previously
// in this code example.
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
else
{
Console.WriteLine("Source path does not exist!");
}
// Keep console window open in debug mode.
Console.WriteLine("Press any key to exit.");
}
}
推荐阅读
- c# - 如何找到失败事件处理程序的来源
- r - 为什么 dplyr :: filter 不允许我用两个垂直进行过滤?
- google-chrome - 如何使我的桌面应用程序与我的插件交互?
- javascript - AES GCM在nodejs中加密并在浏览器中解密?
- android - 少数设备上的一些多边形消失了
- amazon-web-services - 未捕获的类型错误:filesys.existsSync 不是函数
- python - 如何捆绑最少的依赖项以使我的应用程序独立?
- c# - 如何将可绑定对象绑定到 xamarin 表单中的 xml 文件
- python - Python 3 从打印输出创建目录名称
- python - python tkinter单选按钮用按钮更改