Click here to Skip to main content
15,917,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: Rename folder [modified] Pin
netJP12L19-May-09 10:42
netJP12L19-May-09 10:42 
GeneralRe: Rename folder Pin
Moreno Airoldi19-May-09 11:00
Moreno Airoldi19-May-09 11:00 
GeneralRe: Rename folder Pin
netJP12L19-May-09 11:09
netJP12L19-May-09 11:09 
GeneralRe: Rename folder Pin
Eddy Vluggen19-May-09 12:10
professionalEddy Vluggen19-May-09 12:10 
GeneralRe: Rename folder Pin
Moreno Airoldi19-May-09 21:37
Moreno Airoldi19-May-09 21:37 
GeneralRe: Rename folder Pin
Dave Kreskowiak19-May-09 11:05
mveDave Kreskowiak19-May-09 11:05 
GeneralRe: Rename folder Pin
netJP12L19-May-09 11:22
netJP12L19-May-09 11:22 
GeneralRe: Rename folder Pin
Luc Pattyn19-May-09 13:55
sitebuilderLuc Pattyn19-May-09 13:55 
Hi,

you must be doing something special you didn't mention since normally renaming a folder works just fine. Here is test code that works as expected for me:
using (OpenFileDialog d=new OpenFileDialog()) {
    if (d.ShowDialog()==DialogResult.OK) {
        string f=d.FileName;
        log("f="+f);
        string f2=f+"a";
        File.Move(f, f2);
        log("File rename OK");
        string dir=Path.GetDirectoryName(f2);
        log("dir="+dir);
        string dir2=dir+"a";
        Directory.Move(dir, dir2);
        log("Folder renamed to "+dir2);
    }
}


I do have some remarks when looking at your code;

1.
your if(openDialog != null) {openDialog = null;} isn't very useful; first of all, if you want it to be null, just write openDialog = null;. However if openDialog doesn't interest you any more, once your using block is closed, keep the declaration inside the using (as I did).

2.
Calling Dispose() on the subject of a using block is not looking good. The using block is there to take care of it.

3.
Don't call GC.Collect(), the way it works automatically will do a better job if you don't interfere with it.

Now the problem you are having may be caused by something you did not tell us; here are two likely causes:

1.
you did open and not close one of the files inside the path you are trying to rename; e.g. maybe you do a myPictureBox.Image=Image.FromFile(aFileInsideTheChosenFolder);

2.
you did create, write and close a new file inside the folder; although you closed it, some other process may be busy reading the file (an anti-virus scanner, an automatic indexing program, whatever). Try inserting a Thread.Sleep(3000) before you attempt to rename.

Hope this helps.

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

QuestionUmm...wow...request from one of our IBM guys - He needs to send an EBCDIC blob(not converted to ASCII) to be consumed directly by a C# app Pin
Alaric_19-May-09 9:25
professionalAlaric_19-May-09 9:25 
GeneralRe: Umm...wow...request from one of our IBM guys [modified] Pin
led mike19-May-09 10:02
led mike19-May-09 10:02 
GeneralRe: Umm...wow...request from one of our IBM guys Pin
Alaric_19-May-09 10:20
professionalAlaric_19-May-09 10:20 
GeneralRe: Umm...wow...request from one of our IBM guys Pin
led mike19-May-09 11:54
led mike19-May-09 11:54 
AnswerRe: Umm...wow...request from one of our IBM guys - He needs to send an EBCDIC blob(not converted to ASCII) to be consumed directly by a C# app Pin
Luc Pattyn19-May-09 14:07
sitebuilderLuc Pattyn19-May-09 14:07 
AnswerRe: Umm...wow...request from one of our IBM guys - He needs to send an EBCDIC blob(not converted to ASCII) to be consumed directly by a C# app Pin
PIEBALDconsult19-May-09 15:20
mvePIEBALDconsult19-May-09 15:20 
AnswerRe: Umm...wow...request from one of our IBM guys - He needs to send an EBCDIC blob(not converted to ASCII) to be consumed directly by a C# app Pin
Moreno Airoldi20-May-09 1:05
Moreno Airoldi20-May-09 1:05 
QuestionWeb file download from C# console application gets 401 Pin
Mike Devenney19-May-09 9:22
Mike Devenney19-May-09 9:22 
AnswerRe: Web file download from C# console application gets 401 Pin
led mike19-May-09 10:13
led mike19-May-09 10:13 
AnswerRe: Web file download from C# console application gets 401 Pin
Noctris19-May-09 10:25
Noctris19-May-09 10:25 
GeneralRe: Web file download from C# console application gets 401 Pin
Baeltazor19-May-09 17:23
Baeltazor19-May-09 17:23 
GeneralRe: Web file download from C# console application gets 401 Pin
Mike Devenney20-May-09 5:04
Mike Devenney20-May-09 5:04 
QuestionRe: Web file download from C# console application gets 401 Pin
Mike Devenney20-May-09 7:21
Mike Devenney20-May-09 7:21 
Questionreferencing a control from a string Pin
Tom Wright19-May-09 9:17
Tom Wright19-May-09 9:17 
AnswerRe: referencing a control from a string [modified] Pin
Jimmanuel19-May-09 9:46
Jimmanuel19-May-09 9:46 
GeneralRe: referencing a control from a string Pin
Tom Wright19-May-09 10:25
Tom Wright19-May-09 10:25 
GeneralRe: referencing a control from a string Pin
Tom Wright19-May-09 10:27
Tom Wright19-May-09 10:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.