Tuesday 25 August 2015

Rename files or folder using vjslib dll

In this given example we will learn how to rename a file or folder using base vsual basic dll vjslib.
You need to add reference the same dll from your framework or you can download from Microsoft.

Pretty easy Example

       
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
//file rename
public static void FileDRename( string FileNameWithPath, string onlyNewFileName )
            {
                try
                {
                    if( FileNameWithPath != null && onlyNewFileName != null )
                    {
                        if( System.IO.File.Exists( FileNameWithPath ) )
                        {
                            Microsoft.VisualBasic.Devices.Computer a = new Microsoft.VisualBasic.Devices.Computer();
                            string FPath = FileNameWithPath.Substring( 0, FileNameWithPath.LastIndexOf( '\\' ) );
                            string NewFile = FPath + "\\" + onlyNewFileName;
                            if( System.IO.File.Exists( NewFile ) )
                            {
                                System.IO.File.Delete( NewFile );
                            }
                            a.FileSystem.RenameFile( FileNameWithPath, onlyNewFileName );
                        }
                    }
                }
                catch
                {
                }
            }


//directory rename
 public static void DirectoryRename( string directory, string newname )
            {
                if( directory != null && newname != null )
                {
                    if( Directory.Exists( directory ) )
                    {
                        Microsoft.VisualBasic.Devices.Computer a = new Microsoft.VisualBasic.Devices.Computer();
                        a.FileSystem.RenameDirectory( directory, newname );
                    }
                }
            }

       
More method