Author Topic: Problem with Dirrename()  (Read 3582 times)

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Problem with Dirrename()
« on: June 07, 2013, 06:17:10 pm »
I'm trying to work around a problem with Max_Path on Windows XP.

Code: Winbatch
Old = dirget():subDir
dirA = dirget():'A'
dirchange('C:\')
f00 = dirget()          ; Shows the logged drive as C:\
dirrename(Old, dirA)
 

Error: #1025: File Rename: Rename failed
Script: dirrename(Old, dirA)
Assignment:
File: C:\0ser\WinBatch\TestErrorHandling.wbt
Procedure:
Line No. 66

When stepping thru the code names are as expected but the script errors out despite changing to another drive.
Thanks

George

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Re: Problem with Dirrename()
« Reply #1 on: June 09, 2013, 01:40:38 am »
I solved the problem and thought I would post the solution just in case someone else encounters it.  I don't understand why the original script doesn't work but here's the solution.

Originally, the script was trying to do this:
   
Code: Winbatch
dirrename('c:\test\sub', 'c:\test\test')
I also tried this just in case:
Code: Winbatch
dirrename('c:\test\sub\', 'c:\test\test\')
after changing to a different drive.  So here's what worked.
Code: Winbatch
dirchange('c:\test')
dirrename('sub', 'test)


I'd appreciate if someone could explain why the original code failed.  I know that if you're moving a folder you shouldn't be logged to its drive.  Obviously this doesn't apply to renaming a folder.

Thanks

George
Thanks

George

td

  • Tech Support
  • *****
  • Posts: 2769
    • WinBatch
Re: Problem with Dirrename()
« Reply #2 on: June 10, 2013, 07:03:38 am »
Some details are missing but one explanation is that you were attempting to rename a directory located on a volume other than the volume of the process's CWD.  According to MSFT, performing a rename across volumes, apparently including from a different CWD volume, is strictly  verboten.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Re: Problem with Dirrename()
« Reply #3 on: June 11, 2013, 12:01:27 pm »
I made an assumption based on this Tech DB article:
"Also note that DirRemove cannot remove a directory that any program is "logged" to (i.e. has open). So if you have a copy of Windows Explorer looking at a directory, then you cannot DirRemove that directory. "
that this applied to renaming folders as well.

After creating a script to test dirrename and folder locking I discovered that I just need to be logged on to the drive where the folder resides to rename it.  I also discovered that the article no longer applies to removing folders.  It may mess up Explorer, Powerdesk or Directory Opus and they need to be refreshed but they don't prevent the folder from being deleted.
Thanks

George

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Problem with Dirrename()
« Reply #4 on: June 11, 2013, 12:05:08 pm »
I made an assumption based on this Tech DB article:
"Also note that DirRemove cannot remove a directory that any program is "logged" to (i.e. has open). So if you have a copy of Windows Explorer looking at a directory, then you cannot DirRemove that directory. "
that this applied to renaming folders as well.

After creating a script to test dirrename and folder locking I discovered that I just need to be logged on to the drive where the folder resides to rename it.  I also discovered that the article no longer applies to removing folders.  It may mess up Explorer, Powerdesk or Directory Opus and they need to be refreshed but they don't prevent the folder from being deleted.

Thanks for the input. We will look into modifying the article: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Functions+DirRemove~Not~Removing~Directory.txt
Deana F.
Technical Support
Wilson WindowWare Inc.