Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I am brand-new in C# and I wanna do that in C#.
Can you show me the way :)

- Enter a remote machine hostname
- get list folder names in C directory from the remote machine
- select folder names from the list
- delete the selected folders
- show a message about the process (deleted or not)

Is that too hard? Thank you for your help in advance and sory for my bad English :(

What I have tried:

I tried part one part. I dont have information to combine them :(
Posted
v2
Comments
RickZeeland 26-Mar-16 11:20am    
Maybe this might be of interest to you:
http://www.codeproject.com/Articles/9029/Push-and-Run-NET-Code-on-Remote-Machine
F-ES Sitecore 26-Mar-16 12:57pm    
It's not hard, it's simply a case of using the classes in System.IO

https://msdn.microsoft.com/en-us/library/system.io.directoryinfo(v=vs.110).aspx

What's hard is that the code needs to run under an account that has the relevant permissions. By default windows shares the root of each drive as a hidden share (so "c" is shared as "c$") and if you have the right permissions you can access the drives on other machines like this

\\machinename\c$\folder\subfolder

If you don't have the rights on the remove machine then you just can do this, and why not, it would be pretty bad if anyone could list and delete folders on your machine.
What don't you research about one requirement at a time and try some codes. If you face issues, then come back and ask another question with details.

1 solution

There is no such thing as " C directory from the remote machine". There even no such thing as "C directory", even on your local machine. And, just to dismiss the though completely, even on your local Windows system, event the volume "C:" may or may not exist. The whole idea is wrong; this is not how things works.

Generally, with remote computer connected to a network, no computer has access to nothing except some network services. You can access only to some of those services, only if you have enough privileges. And the services can sever up files or not; it depends on the configuration of a remote computer.

With Windows, specifically, you can use its file sharing service, which is always on by default: Enable file and printer sharing[^].

The file names, generally, have nothing to do with original remote computer's file system, they are UNC: Uniform Naming Convention — Wikipedia, the free encyclopedia[^].

The file names are set up when you set up file sharing properties for directories and files. They may or may not follow the original file system structure.

If you use Windows file sharing. You work with shared file exactly in the same way as with local system files. The different story would be if you need to do network discovery. One of the ways to do it is described in this CodeProject article: Network Shares and UNC paths[^].

On other OS… but why should I be concerned with other OS? Well, because you only tagged "C#"; you did not indicate that you only work on Windows and only with Windows. C# can be used in many OS, can't it? Well, in brief: this is a whole different story. For example, please see:
Common file systems and protocols — Wikipedia, the free encyclopedia[^],
Samba (software) — Wikipedia, the free encyclopedia[^],
Network File System — Wikipedia, the free encyclopedia[^].

—SA
 
Share this answer
 
v5

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