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
directory renaming in C#
-
- Cadet
- Posts: 10
- Joined: Fri Jan 13, 2006 3:07 am
- Location: Auckland-NZ ; Islamabad-Pakistan
- Contact:
directory renaming in C#
____
Imran.
<You never know what U can do unless you try>
<work hard, harder untill sweat stings the eye>
Imran.
<You never know what U can do unless you try>
<work hard, harder untill sweat stings the eye>
-
- Site Admin
- Posts: 5132
- Joined: Fri May 02, 2003 10:24 am
- Location: Karachi
- Contact:
Re: directory renaming in C#
Dear imran4sin,
Salam,
Best Regards.
Salam,
Might be given fucntion will help you out.imran4sin wrote:Is there any method available to rename a certain directory?
Code: Select all
system(mv dir newdir)
Farrukh Ahmed
-
- Cadet
- Posts: 10
- Joined: Fri Jan 13, 2006 3:07 am
- Location: Auckland-NZ ; Islamabad-Pakistan
- Contact:
Hi LinuxFreak,
Its on a windows environment.
I could use
This should really rename the folder to the new folder, i need to try it .. will let you know.
cheers.
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.
cheers.
____
Imran.
<You never know what U can do unless you try>
<work hard, harder untill sweat stings the eye>
Imran.
<You never know what U can do unless you try>
<work hard, harder untill sweat stings the eye>
Re: directory renaming in C#
use the method you found: move. the msdn docs say it renames directories as well as moves them.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.
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.");
}
}
}
on unix, at least, move renames instead of moving. just like what msdn's docs say.Moving the directory to another is not an option, constraint is the fize size on remote server + time.
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:~$