Author Topic: A problem with DirMake  (Read 2838 times)

George Vagenas

  • Full Member
  • ***
  • Posts: 102
A problem with DirMake
« on: August 31, 2013, 01:16:04 am »
I have a script which uses
Code: Winbatch
List = FileItemize('*.*')
then uses filters on the list to create sub-folders and move matching files into them.  Recently, I ran the script and kept getting an error which took me quite awhile to figure out.  This code illustrates the problem.
Code: Winbatch
   intcontrol(73, 2, 0, 0, 0)   ; GOSUB error handler.
   ErrorList = ''
   Chk = @false
   ; Create a test folder.
   Dir1 = 'D:\TestDirs'
   ; Create a subfolder.
   Dir2 = ' Test '
   ; This line should cause an error.
   if !direxist(Dir2) then Chk = dirmake(Dir2)
      else Chk = @true
   if !Chk
      pause('Folder_From_fName Error.', 'Could not create folder':@crlf:Root:Dir)
   ; Create some test files.
   fileput('!   test1.txt', 'test1')
   fileput('!   test2.txt', 'test2')
   fileput('!   test3.txt', 'test3')
   fMove = fileitemize('*.txt')
   ; And now we error out!
   filemove(fMove, Dir2, @false)

   if ErrorList!=''
      pause(`Error List on Clipboard!`, `These files were not moved to`:Dir2:@crlf:strreplace(ErrorList,@tab,@crlf))   ;***DEBUG LINE***
   Dirs = diritemize('*.*')
   Cnts = itemcount(Dirs, @tab)
   Test = itemextract(Cnts, Dirs, @tab)
   TestLen = strlen(Test)
   Dir2Len = strlen(Dir2)
   pause(`DEBUG PAUSE`, strCat(`TestLen = `, TestLen, @CRLF, `Dir2Len = `, Dir2Len))   ;***DEBUG LINE***

   if direxist(Dir2) then dirremove(Dir2)     ; Removes the folder that we can't move files to!

   Error = LastError()
   if Error==1003 || Error==1008  ;FileMove: Failed
      ; Deal with it.
      ErrorList = iteminsert(fMove, -1, ErrorList, @lf)
      intcontrol(73, 2, 0, 0, 0)   ; GOSUB error handler.
   ErrInfo = strcat('Error: #', Error, ': ', wberrortextstring, @crlf, 'Script: ', wberrorhandlerline, @crlf, 'Assignment: ', wberrorhandlerassignment, @crlf, 'File: ', wberrorhandlerfile, @crlf, 'Procedure: ', wberrorinsegment, @crlf, 'Line No. ', wberrorhandlerlinenumber, @crlf)
   pause('Error Message on Clipboard', ErrInfo)

This line sets Chk to @true
Code: Winbatch
if !direxist(Dir2) then Chk = dirmake(Dir2)
but Winbatch doesn't create a folder ' Test ' it creates a folder ' Test' and returns @true.  Maybe DirMake(Dir) could throw a minor error when Dir contains trailing spaces or FileMove could be modified to ignore trailing spaces.



  • Sr. Member
  • ****
  • Posts: 330
Re: A problem with DirMake
« Reply #1 on: August 31, 2013, 04:59:09 am »
FWIW, I did a little testing at the command line.  I'm assuming the WB calls are just passthrus to the underlying Windows calls - so the results should be about the same as the command line results.

It looks like leading spaces are preserved, but trailing spaces are silently ignored.

Try (at the CMD.EXE prompt):

md "  Test  "
if exist "  Test" echo Hi

and so on...

George Vagenas

  • Full Member
  • ***
  • Posts: 102
Re: A problem with DirMake
« Reply #2 on: August 31, 2013, 01:28:20 pm »
Yes, I never thought the problem was with Winbatch itself, right down to
if exist " test " echo HI
which gets you a nice HI at the command prompt.
Since posting the problem, I've given it some more thought and now think that DirMake(DIR) should return an error, if DIR has trailing spaces.  I think that having FileMove() silently ignore trailing spaces would not be good practice.



  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: A problem with DirMake
« Reply #3 on: September 03, 2013, 09:59:50 am »
Thank you. The developers have been notified of this request.
Deana F.
Technical Support
Wilson WindowWare Inc.