changing directory in .bat files

  • Hi All,

    I am trying to use to compress some backup files with the 7zip program.

    I am able to compress the files via the command prompt by doing the following

    1. I first of all change the directory by entering ...

    cd\program files\7zip

    2. I press enter

    3 then I enter the following command...

    7z a -t7z C:\offers\datafile.7z "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -p"withoutytreedd" -mhe -r -y

    This compresses the files and add them to datafile.7z

    However when I save

    7z a -t7z C:\offers\datafile.7z "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -p"withoutytreedd" -mhe -r -y

    to a batch file (.bat), it doesn't work.

    My question is 'How do I change the directory within the same batch file so that I can schedule it via windows scheduler?

    I need the batch file to

    1. change the directory

    2. compress the files and add it to the zip file (datafile.7z)

    Thanks for your help

  • First, I have a question. Why arent you using SQL Server Compression when backing up? This generally reduces the backup file size down to less than 20% of what it was.

    As far as running 7z in .bat I just use the full path in executing the 7z. So yours would look something like....

    >"c:\program files\7zip\7z.exe" a -t7z C:\offers\datafile.7z "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\*" -p"withoutytreedd" -mhe -r -y

    John

  • Thanks john for your reply.

    I am compressing the .bak files using sql server.

    I was trying to add all the compressed .bak files to one zipped location and then copy it somewhere elase.

    I just couldn't figure out how to get the .bat file to change the directory once it opened the cmd prompt.

    I will try your method and will get back to you.

    Cheers

    Yadhar

  • Oh. Ok. This should work for you. Works for me. Let me know.

  • Hi John,

    Thank you for your reply.

    It worked!

    Adding "c:\program files\7-zip\7z.exe" to the .bat file changed the directory.

    Thanks once again

    Yarhad

  • Sure. Glad it helped.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply