Click here to Skip to main content
15,902,908 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i have a folder which is in the same directory as my application and i need to move the contents of this folder to another folder which has been selected by the user and the path of this destination folder is displayed in a textbox.


What is needed

1)The application to get its current directory location
2)Access a folder that is in that location (This folder is named folderA)
3)Then to copy the files that are in folderA
4)To the directory which has been set but the user and its path is displayed in a textbox (called opendir)

I am assuming you would pull the destination folder path from opendir.text


C#
string files = System.IO.Directory.GetCurrentDirectory();
            
            try
            {
                Process.Start(Openfile.Text);
                WindowState = WindowState.Minimized;
                Directory.Move(files + @"\FolderA", Opendir.Text);
            }
            catch
            {
                //MessageBox.Show("", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }


This is what i have got so far but i cant seem to direct the program to folderA after the GetCurrentDirectory call.
Posted
Updated 7-Jun-15 1:47am
v5
Comments
[no name] 6-Jun-15 8:22am    
Okay.... and? What you done? Where is the code that you have written? Where is the description of a problem with the code that you have written?
Yusuf_20_x 6-Jun-15 8:25am    
well i did try with with System.IO.Directory.Move(@"FolderA\", Opendir.Text);
[no name] 6-Jun-15 8:29am    
You realize that we cannot see your code, you screen or your hard drive right? Okay so you tried that? What happened when you tried it? You have to tell us this stuff otherwise we have no idea at all what you see on your computer screen.
Yusuf_20_x 6-Jun-15 8:36am    
nothing gets moved over i didn't think i need to show any code because the user sets the destination path which is displayed in the opendir textbox
[no name] 6-Jun-15 10:44am    
So you wrote some code, allegedly, and have a problem with the code you wrote but you don't see the need to show us the code that you wrote and describe an actual problem? Good luck.

Directory.Move will do it, under many conditions. See MSDN for when it won't: https://msdn.microsoft.com/en-us/library/system.io.directory.move(v=vs.110).aspx[^]

Probably, what you need to do is change the Source parameter. Try this:
C#
Directory.Move(Path.Combine(Application.StartupPath, "FolderA"), Opendir.Text);
 
Share this answer
 
Comments
Yusuf_20_x 7-Jun-15 8:11am    
I get error when trying that code something along the lines of sysytem.windows.shapes.path does not contain definition of Combine and the same message but with the definition of startuppath
OriginalGriff 7-Jun-15 8:26am    
Wrong Path: fully qualify it.
System.IO.Path.Combine

https://msdn.microsoft.com/en-us/library/system.io.path(v=vs.110).aspx
Yusuf_20_x 7-Jun-15 8:29am    
yeah thanks but i have just done that and it works writing solution now giving you credit!
Hi,

Apart from the fact that it is clear that you have not googled to find your solution, but you've just asked here hoping that somebody, now or later, will give you a solution here's what you need to do.

First of all I suggest you to read this document from MSDN: https://msdn.microsoft.com/en-us/library/vstudio/ms404278(v=vs.100).aspx[^]. MSDN is a huge website you can find almost everything on it. I haven't looked for a solution on Codeproject, but I assume there is one, there MUST be one.

Secondly, Directory.Move does exactly what you want, so you may want to use a recursive function or a foreach statement or even Microsoft.VisualBasic namespace. Here's a reference http://stackoverflow.com/questions/3911595/move-all-files-in-subfolders-to-another-folder-using-c-sharp[^].

I hope this helps and, a piece of advice for the next times: google for your question: it might have been asked one million times before. Moreover, you will get an answer sooner! :-)

LG
 
Share this answer
 
v2
Comments
Yusuf_20_x 6-Jun-15 14:55pm    
hmm MSDN hope never heard of that site...-_- perhaps when you can get down from your high horse and read my question you will realized that all the solutions that i have googled! have the directories permanently set either in the C drive or other location i have to compensate for the user to move my application to a different directory and to select a different destination directory!
Dave Kreskowiak 6-Jun-15 18:36pm    
Never heard of MSDN?? Really? So where did you get Visual Studio from and why have you never hit the F1 key in it which takes you directly to MSDN?

Yusuf_20_x 6-Jun-15 14:57pm    
Also they move the folder over to the destination directory and not the files listed with in!
LLLLGGGG 7-Jun-15 3:09am    
As I have written in my answer, according to MSDN Directory.Move moves a folder and the files inside it. If you want to move the subfolders too, the easiest way is to use Microsoft.VisualBasic namespace which provides you a lot of simple methods to deal with IO.
I have found the solution with the following code thanks to OriginalGriff
Directory.Move(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "FolderA"), Opendir.Text);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900