Thread: Batch file

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Unhappy Batch File


    There is an excel file for each day of the month. I need to create the Excel file for each day as per the date in current month folder.

    For example: There are 31 days in month of January, so the Excel files in Jan month's folder will be

    01-01-12.xls
    02-01-12.xls
    03-01-12.xls
    ...
    31-01-12.xls

    Is it possible?

    I tried this in a .bat file but I don't know how to construct the loop:

    @For /F "tokens=1,2,3 delims=/" %%A in ('Date /t') do @(
    Set Day=%%A
    Set Month=%%B
    Set Year=%%C
    Set All=%%A%%B%%C
    )

    @For %%a in ("*.xls") do copy %%a "import\%All%.xls"
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    I have no idea what you want to do. Try explaining it again and I'll try to give you the right PHP answer.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Smile


    Hi,

    Thanks for rplying, I will try to explain again.
    There is one Master excel file in an folder. And i want copy this master file and create an copy with the file name as the date.

    In this example say the file name goes like 02-03-12.xls. Now with the help of batch file i want to create excel file for each day of the month. like
    03-03-12.xls
    04-03-12.xls
    05-03-12.xls
    06-03-12.xls
    Till 31-03-12(31st march)

    Hope you understood.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    So starting from today until the end of the month?
    PHP Code:
    $format "%02d-" date("m-y");
    $end date("n");
    for (
    $n date("d"); $n <= $end$n++) {
        
    copy("path/to/master.xls"sprintf("path/to/destination/folder/$format.xls"$n));

    There's a quick PHP solution.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0
    Hi,

    Thanks for your answer,
    I needed the same in Batch file not in PHP Langauge.
    Need something Where will write the code in notpad and save the file in .bat extension.

    Thanks for understanding
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    Originally Posted by uday100
    I needed the same in Batch file not in PHP Langauge.
    Oh... Then why did you post in the PHP forum?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0
    Sorry,
    Just registered in this site. Didn't knew where to go...
  14. #8
  15. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    The forum listing would be a good idea. In there is Windows Help, which would seem a much more appropriate place for this question.

    But I've moved this thread there so you don't need to do anything.
  16. #9
  17. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    With that out of the way,

    Can you use PowerShell instead of a batch file? The problem is that there's no built-in command to Windows (that I know of) that can tell you how many days there are in the current month; without that the script can't know how many files need to be copied.

    Or you could simply create 31 of them every time and manually delete the ones that don't belong, but that's probably not a good option.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Unhappy Batch file


    There is an excel file for each day of the month. I need to create the Excel file for each day as per the date.For example: There are 31 days in month of January, so the Excel files in each month's folder will be
    01-01-12.xls
    02-01-12.xls
    03-01-12.xls
    ...
    31-01-12.xls

    Is it possible?

    I tried the below code, but the valuve after ECHO are coming as blank. Can anyone help. Mine pc is in American format or dd-mm-yy

    @echo off
    set /P max=How many Days this month:

    for /f "tokens=2-9 delims=/ " %%a in ('date /T') do @(
    REM @For /F "tokens=1,2,3 delims=/" %%A in ('Date /t') do @(
    set y=%%c
    set m=%%a
    set d=%%b
    )

    echo The Month is %m%
    echo The Day is %d%
    echo The Year is %y%
    echo the Month is %max% days long
    set d=01
    Set /a max=%max%+1

    :loop

    for /l %%G in (d,1,max) do @(SET date=%d%-%m%-%y%

    copy "C:\Documents and Settings\Desktop\hi\act\*.xls" "C:\Documents and Settings\NGLD7640\Desktop\hi\act\%date%.xls"

    set /a d=%d%+1

    if not %d%==%Max% goto loop
    )
    pause > nul

IMN logo majestic logo threadwatch logo seochat tools logo