Re: Very weird DOS error




"Wowbagger" <none> wrote in message
news:eHpO%23Ih9FHA.1520@xxxxxxxxxxxxxxxxxxxxxxx
>I have a batch file used to sort lots and lots of files into various
>directories alphabetically.
>
> The batch file reads as follows:
> {batch starts}
>
> cd \picdir
>
> if not exist thumbs.db GOTO main
>
> attrib -s -h thumbs.db
> del thumbs.db
>
> :main
> if not exist #Numbered GOTO error_missing_dir
> if exist 0*.* move 0*.* #Numbered
> if exist 1*.* move 1*.* #Numbered
> if exist 2*.* move 2*.* #Numbered
> if exist 3*.* move 3*.* #Numbered
> if exist 4*.* move 4*.* #Numbered
> if exist 5*.* move 5*.* #Numbered
> if exist 6*.* move 6*.* #Numbered
> if exist 7*.* move 7*.* #Numbered
> if exist 8*.* move 8*.* #Numbered
> if exist 9*.* move 9*.* #Numbered
>
> if not exist -a-c GOTO error_missing_dir
> if exist a*.* move a*.* -a-c
> if exist b*.* move b*.* -a-c
> if exist c*.* move c*.* -a-c
>
> if not exist -d-f GOTO error_missing_dir
> if exist d*.* move d*.* -d-f
> if exist e*.* move e*.* -d-f
> if exist f*.* move f*.* -d-f
>
> if not exist -g-i GOTO error_missing_dir
> if exist g*.* move g*.* -g-i
> if exist h*.* move h*.* -g-i
> if exist i*.* move i*.* -g-i
>
> if not exist -j-l GOTO error_missing_dir
> if exist j*.* move j*.* -j-l
> if exist k*.* move k*.* -j-l
> if exist l*.* move l*.* -j-l
>
> if not exist -m-n GOTO error_missing_dir
> if exist m*.* move m*.* -m-n
> if exist n*.* move n*.* -m-n
>
> if not exist -o-r GOTO error_missing_dir
> if exist o*.* move o*.* -o-r
> if exist p*.* move p*.* -o-r
> if exist q*.* move q*.* -o-r
> if exist r*.* move r*.* -o-r
>
> if not exist -s-t GOTO error_missing_dir
> if exist s*.* move s*.* -s-t
> if exist t*.* move t*.* -s-t
>
> if not exist -u-x GOTO error_missing_dir
> if exist u*.* move u*.* -u-x
> if exist v*.* move v*.* -u-x
> if exist w*.* move w*.* -u-x
> if exist x*.* move x*.* -u-x
>
> if not exist -y-z GOTO error_missing_dir
> if exist y*.* move y*.* -y-z
> if exist z*.* move z*.* -y-z
>
> GOTO END
>
> :error_missing_dir
> @echo ERROR! Destination directory missing. Process halted.
>
> :END
> pause
> {batch ends}
>
> The weird error manifests as follows (I turned on the echo, this is a
> capture from the window showing the output of the relevant lines):
>
> X:\picdir>if not exist -s-t GOTO error_missing_dir
> X:\picdir>if exist s*.* move s*.* -s-t
> X:\picdir>if exist t*.* move t*.* -s-t
> The filename, directory name, or volume label syntax is incorrect.
> X:\picdir>if not exist -u-x GOTO error_missing_dir
> X:\picdir>if exist u*.* move u*.* -u-x
>
> What is so special about t*.*?
>
>

Nothing at all.

What you probably have is a directory named t* - which IF EXISTS will
detect, but isn't a file so MOVE can't move it.

Try:

[1]@echo off&setlocal enabledelayedexpansion
[2]for /f "delims=" %%i in ('dir /b /a-d *.*') do set yFN=%%i&call
:process&echo move "%%i" !yDD!
[3]goto :eof
[4]
[5]:process
[6]set yC1=%yFN:~0,1%&set yDD=unknown
[7]if /i %yC1% GEQ 0 if /i %yC1% LEQ 9 set yDD=#Numeric
[8]if /i %yC1% GEQ G if /i %yC1% LEQ I set yDD=-g-i
[9]if /i %yC1% GEQ S if /i %yC1% LEQ T set yDD=-s-t
[10]md %yDD% 2>nul
[11]goto :eof

Each line begins [number]. Lines will be wrapped in transmission and need to
be rejoined. The [number] at the beginning of each line needs to be removed.

Notes :

[1] setlocal ... allows the instantaneous value of a variable to be used
(!varname!) rather than the parse-time value
As a bonus, SETLOCAL ensures that environment changes made by the script are
dropped when the process terminates.
[2]will ECHO the required command. Remove the ECHO keyword to perform the
MOVE.
[3],[11] NT+ defines ":eof" (specifically with the colon) as
"end-of-script-file". [11] is redundant but good practice (IMHO)
[6]sets envvar yC1 to the first character of the filename in yFN, then sets
the destination directoryname yDD to a default destination-directory
[8],[9] - pattern for -g-i, -s-t. Not a big problem for you to complete...
[10] create the destination directory & suppress the error message if it
already exists.
if not exist %yDD%\. md %yDD%
would also probably work here

You may be interested in the batch discussion group alt.msdos.batch.nt

HTH

....Bill


.



Relevant Pages

  • Re: Batching Updates?
    ... If you batch run them, they will automatically wait for one to finish before ... Echo Applying IE 5.5 Post-SP2 Hotfixes to system. ... Echo Reboot to activate changed files. ... >>the network login script or a batch file run on the ...
    (microsoft.public.security)
  • Re: Multi-zip files -- Windows server
    ... native DOS versions). ... TO BATCH OR NOT TO BATCH ... and using a batch file to try and solve the problem... ... The IBM PC operating system command line is a most ...
    (comp.sys.cbm)
  • Re: EWF RAM
    ... Do you mean it is running the stress test fine locally on the device? ... If it does and the issue has no repro, you should move to use local batch file approach in your support scenario. ... >> A tech plugs into it with laptop and remote desktops to it. ...
    (microsoft.public.windowsxp.embedded)
  • Re: Windows "Scheduled Task Wizard..."
    ... Do you know any links at Microsoft documents related to the batch file ... command name to get started. ... VB Script and any other Microsoft scripting languages have nice ...
    (microsoft.public.windows.server.general)
  • Re: Command prompt tool to minimize a command window AFTER it starts?
    ... > running CMD.exe in an open window which has the annoying habit of coming ... > minimize it -- my intent is to run it as the first line of the batch. ... You can rewrite the main Batch file as a Subroutine shell, ... ECHO command): ...
    (microsoft.public.win2000.cmdprompt.admin)