directory renaming in C#

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

directory renaming in C#

Postby imran4sin » Sat Feb 04, 2006 2:35 pm

Is there any method available to rename a certain directory?

I've looked under Directory and DirectoryInfo but cant find much on renaming the directory.

Moving the directory to another is not an option, constraint is the fize size on remote server + time.
thanks.

PS: havent checked google yet
____
Imran.
<You never know what U can do unless you try>
<work hard, harder untill sweat stings the eye>
imran4sin
Cadet
 
Posts: 10
Joined: Fri Jan 13, 2006 3:07 am
Website: http://au.pg.photos.yahoo.com/ph/netstud69/album?.dir=/f0e6&.src=ph
WLM: imrandman2@hotmail.com
Location: Auckland-NZ ; Islamabad-Pakistan

Re: directory renaming in C#

Postby LinuxFreaK » Sat Feb 04, 2006 7:43 pm

Dear imran4sin,
Salam,

imran4sin wrote:Is there any method available to rename a certain directory?


Might be given fucntion will help you out.

Code: Select all

system(mv dir newdir)


Best Regards.
Farrukh Ahmed
LinuxFreaK
Site Admin
 
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi

Postby imran4sin » Sun Feb 05, 2006 2:20 am

Hi LinuxFreak,
Its on a windows environment.


I could use

Code: Select all

public static void Move ( System.String sourceDirName , System.String destDirName )
    Member of System.IO.Directory

Summary:
Moves a file or a directory and its contents to a new location. 


This should really rename the folder to the new folder, i need to try it .. will let you know.
cheers.
____

Imran.

<You never know what U can do unless you try>

<work hard, harder untill sweat stings the eye>
imran4sin
Cadet
 
Posts: 10
Joined: Fri Jan 13, 2006 3:07 am
Website: http://au.pg.photos.yahoo.com/ph/netstud69/album?.dir=/f0e6&.src=ph
WLM: imrandman2@hotmail.com
Location: Auckland-NZ ; Islamabad-Pakistan

Re: directory renaming in C#

Postby lambda » Sun Feb 05, 2006 2:36 am

imran4sin wrote:Is there any method available to rename a certain directory?

I've looked under Directory and DirectoryInfo but cant find much on renaming the directory.

use the method you found: move. the msdn docs say it renames directories as well as moves them.

Code: Select all

using System;

class MV
{
    static void Main(string[] args)
    {
        if (args.Length < 2) {
            System.Console.WriteLine("mv.exe old-dir new-dir");
            return;
        }
        mv(args[0], args[1]);
    }

    static void mv(string olddir, string newdir)
    {
        try  {
                    System.IO.Directory.Move(olddir, newdir);
                }
        catch (Exception) {
            System.Console.WriteLine("error, couldn't mv.");
        }
    }
}

Moving the directory to another is not an option, constraint is the fize size on remote server + time.

on unix, at least, move renames instead of moving. just like what msdn's docs say.

Code: Select all

fn@r50e:~$ mkdir a a/b
fn@r50e:~$ touch a/file1 a/b/file2
fn@r50e:~$ ls -laRi a
a:
total 12
547466 drwxr-xr-x   3 fn fn 4096 2006-02-05 02:29 .
353410 drwxr-xr-x  24 fn fn 4096 2006-02-05 02:29 ..
547467 drwxr-xr-x   2 fn fn 4096 2006-02-05 02:29 b
547468 -rw-r--r--   1 fn fn    0 2006-02-05 02:29 file1

a/b:
total 8
547467 drwxr-xr-x  2 fn fn 4096 2006-02-05 02:29 .
547466 drwxr-xr-x  3 fn fn 4096 2006-02-05 02:29 ..
547469 -rw-r--r--  1 fn fn    0 2006-02-05 02:29 file2
fn@r50e:~$ ./mv.exe a c
fn@r50e:~$ ls -laRi c
c:
total 12
547466 drwxr-xr-x   3 fn fn 4096 2006-02-05 02:29 .
353410 drwxr-xr-x  24 fn fn 4096 2006-02-05 02:29 ..
547467 drwxr-xr-x   2 fn fn 4096 2006-02-05 02:29 b
547468 -rw-r--r--   1 fn fn    0 2006-02-05 02:29 file1

c/b:
total 8
547467 drwxr-xr-x  2 fn fn 4096 2006-02-05 02:29 .
547466 drwxr-xr-x  3 fn fn 4096 2006-02-05 02:29 ..
547469 -rw-r--r--  1 fn fn    0 2006-02-05 02:29 file2
fn@r50e:~$
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby imran4sin » Sun Feb 05, 2006 9:32 am

yes.. move worked nicely... as expected.

I was making a silly mistake of using the wrong function .. must have done it --late night.

anyhow.. cheers.
____

Imran.

<You never know what U can do unless you try>

<work hard, harder untill sweat stings the eye>
imran4sin
Cadet
 
Posts: 10
Joined: Fri Jan 13, 2006 3:07 am
Website: http://au.pg.photos.yahoo.com/ph/netstud69/album?.dir=/f0e6&.src=ph
WLM: imrandman2@hotmail.com
Location: Auckland-NZ ; Islamabad-Pakistan


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron