移动文件并保留路径 [英] Moving files and keeping paths

查看:118
本文介绍了移动文件并保留路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个程序,用于移动早于所选日期的文件.我的问题是我需要保持/制作文件之前的相同路径.即

要移动的文件位于"c:\ backup \"中,我选择将找到的文件移至"f:\ gigastorage \",该程序现在需要先创建"f:\ gigastorage \ backup \",然后再移动文件.

我移动了文件,但它们没有保留其原始路径.有人解决了吗?

I''m making a program that moves files that is older than a choosen date. My problem is that i need to keep/make the same path the files had before they where moved. i.e

File to be moved is in "c:\backup\" and i choose that files that are found should be moved to "f:\gigastorage\" the program now need to create "f:\gigastorage\backup\" before moving the file.

I get the files moved but they don''t keep their original paths. Anyone got a solution for this?

推荐答案

调用File.Move方法时必须指定路径.
因此,您要剥离"C:"部分(在源路径中找到"\"或"/"的第一个实例,并将其用作Substring操作的开始).然后将其附加到目标路径.
You have to specify the path when you call the File.Move method.
So, you want to strip off the "C:" part (find the first instance of ''\'' or ''/'' in the source path, and use that as the start of a Substring operation). Then append that to the destination path.


这篇关于移动文件并保留路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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