dimanche 10 mai 2015

writing a batch file to input path and filename, get size and date of file, then sort

I have created a file with path and filename. I am passing the file names, via the command line, one at a time my batch file. I am using the %~1, %~t1, %~z1 to obtain the time and size values. I want to write each record to a file for sorting. The time and file sizes will be different and I want to save the version with the best information.

I am having problems in the batch file to get the size and date. I am trying to test if I get an error reading the information for the file. When I look at the parameter it always contains the path filename passed to the batch file. When printing the %~t1 an %~z1 values if every thing is normal I see the correct values else the print just shows time = and size =. Therefore I am trying to use the file size or time value to determine if there was an error.

I have tried many different ways to use an IF cmd to print out that an ERROR occurred or not. I have not used batch file in a while and I can not figure out what is causing the problems.

This is a snippet from the batch file (with some of the things I have tried):

@echo off

rem if [%~z1] == []
rem if [NOT] %~t1
rem if ["%~t1]==[]
rem if exist [%~1] 
 str1 = %~t1
 if not definded str1 (echo str1 error)
 if not definded str1
(   print "AN ERROR OCURRED  FOR THIS FILE/n"  )
else
(   
    echo fpath =%~1 
    echo time = %~t1   
    echo size = %~z1   
)

I get: - ) was unexpected at this time -The syntax of the command is incorrect -EXIST was unexpected at this time -unable to initialize device PRN. 'else' is not recognized as an internal or external command -str1 is not recognized as an internal or external command, .. str1 was unexpected at this time

These are probably my errors but searching many information sites is not ringing a bell in my head as to what I am doing wrong.

Any help would be appreciated. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire