Remove Dirs

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Remove Dirs

Post by Knoore » Thu Dec 07, 2006 1:14 pm

How can i remove dirs in Macro Scheduler
Currently i use this
Let>cmdcmd=cmd /c RMDIR /S /Q %subsubdir%
Run>cmdcmd
But if the dirname is longer then 8 chars then i get a error (dos restrictions)
So now i'm wonder how can i remove dirs good and fast?
Cause something i have to remove like 200 dirs, then it runs the CMD 200 times ;)

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 07, 2006 1:50 pm

There's no reason DOS won't remove your directories. Try these changes (in red):

Let>cmdcmd=cmd /c RMDIR /S /Q "%subsubdir%"
Let>RP_WAIT=1
Run>%cmdcmd%

Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Post by Knoore » Thu Dec 07, 2006 3:32 pm

With short folder names it works
but if the variable subsubfolder gets long, then CMD gives error (folder/file) not found

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Dec 07, 2006 3:50 pm

Did you try with quotes around %subsubdir% as JRL suggested:

Let>cmdcmd=cmd /c RMDIR /S /Q "%subsubdir%"
Let>RP_WAIT=1
Run>%cmdcmd%
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 07, 2006 3:51 pm

What is your operating system?

another thought... Are these directories on a drive that is formated to Fat32?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 07, 2006 5:15 pm

Since you seem to be in a situation where you are dealing with short file names, try this. It works on my WinXP computer.

You need to specify [drive]:\[path]\ and you may need to specify it in the short filename format.

Code: Select all

Let>RP_WAIT=1
Run>cmd /c dir "[drive]:\[path]\*.*" /ad /X /N >%TEMP_DIR%~directorylist~
Let>_counter_=0
Label>start
add>_counter_,1
ReadLn>%TEMP_DIR%~directorylist~,%_counter_%,line
If>line=##EOF##,done
If>line=,start
midstr>line,1,1,test
If>%test%=%SPACE%,start
midstr>line,53,1,test
If>%test%=.,start
midstr>line,40,1,test
If>%test%=%SPACE%
  midstr>line,53,100,subsubdir
Else
  midstr>line,40,12,subsubdir
EndIf
Let>test=
Let>line=
Let>cmdcmd=cmd /c RMDIR /S /Q "[drive]:\[path]\ %subsubdir%"
Run>%cmdcmd%
Goto>start
Label>done

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 07, 2006 6:23 pm

Looking at this further I've discovered a problem with "RMDIR /S" and DOS generated short directory names. If the directory is empty RMDIR will delete it no matter how you specify the name. However if the directory is not empty "RMDIR /S will only remove the directory if you specify the full name. In other words:

A directory named C:\My Files, that contains files and/or directories, can be removed if you use the line
RMDIR /S "C:\My Files"

If that same directory has a DOS generated short file name of myfile~1 and it contains files and/or directories the line:
RMDIR /S myfile~1
will error with "The directory is not empty"

If you have a copy of "DELTREE.EXE" that shipped with Windows 95, you can use it instead of RMDIR /S. DELTREE,EXE has worked on every windows operating system since Win95. The same code from above would be ammended to:

Code: Select all

Let>RP_WAIT=1
Let>RP_WINDOWMODE=1
Run>cmd /c dir "[drive]:\[path]\*.*" /ad /X /N >%TEMP_DIR%~directorylist~
Let>_counter_=0
Label>start
add>_counter_,1
ReadLn>%TEMP_DIR%~directorylist~,%_counter_%,line
If>line=##EOF##,done
If>line=,start
midstr>line,1,1,test
If>%test%=%SPACE%,start
midstr>line,53,1,test
If>%test%=.,start
midstr>line,40,1,test
If>%test%=%SPACE%
  midstr>line,53,100,subsubdir
Else
  midstr>line,40,12,subsubdir
EndIf
Let>test=
Let>line=

Let>cmdcmd=cmd /c "[Drive]:\[Path]\deltree.exe" /Y "[Drive]:\[Path]\%subsubdir%"

Run>%cmdcmd%
Goto>start
Label>done

Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Post by Knoore » Fri Dec 08, 2006 10:35 am

Aint it possible to remove the dir with VB or something?

VBSTART
Sub dirremove (dir)
RmDir dir
End Sub
VBEND

VBRun>dirremove,subsubdir

This gives an error, but i dont know why, does any1 know how to fix it?

Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Post by Knoore » Sat Dec 09, 2006 12:35 pm

Any1?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Dec 09, 2006 4:26 pm

I am curious about what happens if you use deltree? Usually quite effective in pruning directory trees.

JRL provided a method that uses that.
Did his method not work?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Post by Knoore » Sat Dec 09, 2006 5:28 pm

He is going to send me a copy of Deltree.exe

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Dec 09, 2006 8:08 pm

Available download at: http://www.uv.tietgen.dk/staff/mlha/Dow ... S/#DELTREE
May not work on XP/2K systems with NTFS formats

Deltree NT for NTFS was available at:
http://www.freedownloadscenter.com/Util ... EE_NT.html

-----------------------
Edited 4:55 pm - The link for Deltree NT appears to be "not found". Try to google for "DELTREE NT" for alternate link....
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts