Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2010
    Location
    Oregon
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Multiple percent signs in batch file

    I need to execute the ADFind command-line utility (Link) from a batch file, but one of the switches I need involves many percent signs. Specifically, the " -tdcsfmt" switch has the following default format:
    Code:
    %YYYY%/%MM%/%DD%-%HH%:%mm%:%ss% %TZ%
    I need to do the following within a batch file
    Code:
    adfind -tdcas -tdcsfmt "%YYYY%/%MM%/%DD%-%HH%:%mm%:%ss%" -h nke-win-adc-p03 f ... -csv >OutputFile.csv
    Since percent signs denote a DOS parameter, one would normally double them up, but that doesn't work, either.
    The command works fine when executed directly from the command prompt.
    Any ideas on how to accomplish this greatly appreciated.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,565
    Thanks
    384
    Thanked 1,480 Times in 1,346 Posts
    Reid,

    It seems to work ok for me:
    reid1.JPG
    Test Code:
    Code:
    @Echo OFF
    cls
    Set YYYY=2014
    Set MM=OCT
    Set DD=14
    Set HH=12
    Set mm=15
    Set ss=00
    Echo. The Path is:  %YYYY%/%MM%/%DD%-%HH%:%mm%:%ss%
    Echo. The Path is:  "%YYYY%/%MM%/%DD%-%HH%:%mm%:%ss%"
    Could you post the entire command file so we can see everything that is going on? It's pretty hard to debug when you can't see how the parameters were set up.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,454
    Thanks
    33
    Thanked 196 Times in 176 Posts
    I agree with RetiredGeek that what you have written should and does work.

    Here is my supposed 'universal' date and time code for today and now:
    Code:
    :: generalised DATE and TIME routine for all regions
    ::   %yy% will contain four digits, 20nn;
    ::   %mm%, %dd% and time variables %hr%, %mn%, %sc% and %th% contain two digits
    if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
    for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
       for /f "tokens=%toks% delims=.-/ " %%e in ('date /t')     do (
          for /f "tokens=5-8 delims=:., " %%i in ('echo.^|time') do (
            (set %%a=%%e) & (set %%b=%%f) & (set %%c=%%g) & rem create yy, mm, dd
            (set hr=%%i)  & (set mn=%%j)  & (set sc=%%k)  & (set th=%%l)
            rem  note the variable names for Time: hr, mn, sc, th
    )))
    if 1%yy% LSS 200 (set yy=20%yy%) & :: ensure 4-digit years in %yy%
    if 1%hr% LSS 20  (set hr=0%hr%)  & :: ensure 2-digit hours in %hr%
    
    echo Date is: %yy%-%mm%-%dd%  Time is: %hr%:%mn%:%sc%.%th%
    It was written about the time of the millennium, hence the concern with four-digit years!
    Last edited by BATcher; 2014-11-14 at 03:34.
    BATcher

    "The trouble with quotes on the internet is that you can never know if they are genuine."
    Abraham Lincoln
    

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,444
    Thanks
    52
    Thanked 1,028 Times in 956 Posts
    My reading of your requirements along with a bit of testing produces the following possibility:
    adfind -tdcas -tdcsfmt %YYYY%/%MM%/%DD%-%HH%:%mm%:%ss% -h nke-win-adc-p03 –f ... -csv >OutputFile.csv
    This assumes you do not have any variables set with the names YYYY, MM, DD, HH, mm & ss.
    You don't need to quote the format because there are no spaces or quotes etc.

    cheers, Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •