文件夹和文件操作 [英] Folder and file operations

查看:50
本文介绍了文件夹和文件操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 VB 新手,但我需要使用 VB 在我的项目中实现这些.

I am new to VB but I need to achieve these in my project using VB.

我在本地有一个文件 target.file.网络服务器上有一个 target 文件夹.target 下有几百个文件夹.其中一些文件夹下有 backup 文件夹.

I have a file target.file at local. There is a target folder on network server. There are several hundred folders under target. There are backup folders under some of those folders.

我需要将 target.file 复制到 target 文件夹下的那些文件夹,但如果已经有 target.file 现有.如果target.file存在,如果备份文件夹存在,则将文件复制并替换到备份文件夹.如果没有,请先创建备份文件夹.

I need to copy target.file to those folders under the target folder, but only copy/replace if there is already a target.file existing. If the target.file exists, copy and replace the file to the backup folder if the backup folder exists. If not, create the backup folder first.

推荐答案

您需要使用 System.IO 命名空间中的方法.查看文档,有很多有趣有用的类,特别是文件目录路径.

You need to use the methods in System.IO namespace. Take a look at the Documentation, there is a lot of interesting and useful classes, specially File, Directory and Path.

以下是您需要的方法:

但是,您无需检查文件是否存在,因为您可以在启用覆盖选项的情况下直接复制:

However, you didn't need to check if the file exists because you can copy directly with the overwrite option enabled:

File.Copy(sourceFile, destPathFile, True) 'True for overwrite

这篇关于文件夹和文件操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆