2009-10-22 47 views
0

我有一個批處理文件下:在批處理文件試圖改變

@echo off 
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\vipul.zip" files vipul.xls 
copy vipul.zip "C:\Documents and Settings\vipul\Desktop\My briefcase" 
copy vipul.zip "E:\Valuations\2009" 
exit 

這裏vipul.xls是我的桌面上的文件,該文件被複制到我的公文包,同樣是被ziiped,然後發送到E \ valu ...文件夾。 每次文件名發生變化時,我想在這裏進行的修改如下: 它可能是sanj.xls或lago.xls等等。 (代替vipul.xls),那麼我該怎麼做呢? 就像存在於XP printdir.bat文件

回答

0

可以使用這個批處理文件,這對於任何文件,.xls擴建工程:

@echo off 
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\worksheets.zip" files *.xls 
copy worksheets.zip "C:\Documents and Settings\vipul\Desktop\My briefcase" 
copy worksheets.zip "E:\Valuations\2009" 
exit 

或者,如果只是一個可以在一段時間存在的文件:

@echo off 
set filename= 
if exists vipul.xls set filename=vipul 
if exists sanj.xls set filename=sanj 
if exists lago.xls set filename=lago 
if "%filename%" == "" goto end 
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\%filename%.zip" files %filename%.xls 
copy %filename%.zip "C:\Documents and Settings\vipul\Desktop\My briefcase" 
copy %filename%.zip "E:\Valuations\2009" 
exit 
:end 
+0

但親愛的,我有很多的文件在我的桌面上。我想只有一個文件waork,可能是VIPUL。xls左右 – Vipul 2009-10-22 10:51:17

0

它沒有測試,但是這應該可以幫助您:

@echo off 

REM check if supplied file name actaully exists 
IF "%1"=="" GOTO END 
IF NOT EXIST "%1" GOTO END 

REM define output file name. Use supplied files name without extension and add ".zip" 
SET OutputPath=C:\Documents and Settings\vipul\Desktop\%~n1.zip 

"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "%OutputPath%" files "%1" 
copy "%OutputPath%" "C:\Documents and Settings\vipul\Desktop\My briefcase" 
copy "%OutputPath%" "E:\Valuations\2009" 

:END 

此批處理使用第一個命令行參數(%1)作爲要打包和複製的文件的輸入。第一個IF語句檢查文件是否有效。 SET命令使用要創建的文件的名稱(zip文件)設置變量。其餘部分主要是您已有的代碼,但現在使用這些變量。

編輯:

調用的批處理PROGRAMM,讓我們將其命名爲package.bat,使用的語法如下:

package "C:\Documents and Settings\vipul\Desktop\vipul.xls" 

package "C:\Documents and Settings\vipul\Desktop\sanj.xls" 

您還可以使用可拖放並簡單地將想要處理的文件放在批處理文件package.bat上以啓動它。

如果不起作用,請添加評論。

編輯:

要使用這個批處理文件在你發送到上下文菜單中執行以下步驟:

  1. 保存在一個文件名package.bat上面的代碼(或其他任何你想要的)
  2. 放在你想要的位置。
  3. 創建一個鏈接到該批處理文件package.bat(右鍵單擊該文件,選擇創建鏈接)
  4. 移動所創建的鏈接文件到您的發送到文件夾(如C:\Documents and Settings\vipul\SendTo
  5. 現在你可以選擇任何文件,你想從您的背景下選擇了批處理文件命令菜單 - >發送到

希望有所幫助。

+0

先生,作爲一個非常新的批處理文件命令,很難理解上面的我。我可以有一個類似於printdir.bat的命令嗎?通過這個命令,我可以右鍵單擊單個文件,然後從上下文菜單運行命令,以便它將zip文件,發送到公文包,然後直接發送到e:\ bvaluation文件夾... – Vipul 2009-10-22 11:41:10

+0

我不知道「printdir.bat」,但爲了實現這種行爲,只需在「C:\ Documents and Settings \ vipul \ SendTo」文件夾中添加一個到您的批處理文件的鏈接即可。 – 2009-10-22 12:01:18

+0

ru告訴我必須將vipul.xls拖放到以下批處理文件: @echo off REM檢查提供的文件名是否存在 如果「%1」==「」GOTO END IF NOT EXIST「%1」GOTO REM REM定義輸出文件名。使用提供的文件名不帶擴展名並添加「.zip」 SET OutputPath = C:\ Documents and Settings \ vipul \ Desktop \%\ n1.zip 「C:\ Program Files \ WinZip \ WINZIP32.EXE」-min -a %OutputPath「文件」%1「 copy」%OutputPath「」C:\ Documents and Settings \ vipul \ Desktop \ My briefcase「 copy」%OutputPath「」E:\ Valuations \ 2009「 :END – Vipul 2009-10-22 12:05:39