Page 1 of 1

What is dropped on this batch: file or folder? (a solution)

Posted: 29 Mar 2008 20:44
by budhax

Code: Select all

ECHO.[%1]
ECHO.
IF /i "%1"=="" (ECHO.*** USAGE: DRAG ^& DROP a File or Folder on This BATCH!
) ELSE (IF EXIST "%1\" (ECHO.This is a Folder.) ELSE (ECHO.This is a File.))
Pause&EXIT


The idea to distinguish folders and files is to add a back slash next the parameter: "%1\"
in the IF test.
Any comment?

Posted: 07 Apr 2008 17:36
by jaffamuffin
Looks good. Have a play about with this and see if you get something you like?: Drag and drop a file or dir to see.

Code: Select all

ECHO FILE ATTRIBUTES
echo %~a1
PAUSE


This could be useful for something I'm working on.

This reads in a drag and dropped bunch of image files (e.g. dsc_0411.tif) and sorts them into an order as depending on which file you click on when you drag the selection and the sort order you can't tell which file will be under which parameter.

I needed to have an even set of images (duplex scanned images) so there's a check for that.

Code: Select all

@echo off

IF "%~1" EQU "" ECHO NO PARAMS  & PAUSE
SET count=100
:readParams
   SET /A count=%count% + 1
   ECHO Reading: %1
   SET params.%count%=%~1
   SHIFT
IF NOT "%~1" EQU "" GOTO :readParams
SET totalparams=%count%
SET evenCheck=%count:~-1%
SET oddCount=0
FOR %%A IN (1 3 5 7 9) DO (
   IF %evenCheck% EQU %%A SET oddCount=1
)
IF %oddCount%==1 ECHO Number of params in ODD & PAUSE
ECHO Done.
PAUSE

ECHO Checking:



ECHO Total Params = %totalparams:~-2%
SETLOCAL ENABLEDELAYEDEXPANSION
SET count=101
SET side=1
FOR /F "delims=" %%G IN ('sortparams.bat ^| sort') DO (
   SET paramsSort.!count!_!side!=%%G
   IF !side! EQU 2 (
      SET /A count=!count! + 1
      SET side=1
   ) ELSE (
      SET side=2
   )
)
SET paramsSort.



PAUSE


sortparams.bat:

Code: Select all

@echo off
FOR /F "tokens=2* delims=.=" %%A IN ('SET params.') DO ECHO %%B

Posted: 07 Apr 2008 18:07
by jaffamuffin

Code: Select all

@ECHO off
SETLOCAL
SET attributes=%~a1
SET dirAttrib=%attributes:~0,1%
IF %dirAttrib%==d ( ECHO DIR ) ELSE ( ECHO FILE )
PAUSE

Try this.