Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Скриптовые языки администрирования Windows (http://forum.oszone.net/forumdisplay.php?f=102)
-   -   [решено] Батник шифрования файла (http://forum.oszone.net/showthread.php?t=333593)

s-urbanas 06-03-2018 12:34 2801906

Батник шифрования файла
 
Дан скрипт, который шифрует файлы с помощью утилиты командной строки zpki1utl. Как отредактировать команду, чтобы при шифровании у файла не отрезалось расширение? Например при шифровании файла Test.txt, мы получаем сейчас файл Test.p7e, а хотим получить Test.txt.p7e

@echo off
rem set targetDir=%1
rem if [%targetDir%] == [] (
rem @echo no parameters specified! please, run the script as following:
rem @echo.
rem @echo 1.bat targetDirectory
rem @echo.
rem @echo where:
rem @echo targetDirectory - directory containing files to be processed
rem exit(1)
rem )
set sourceDir=C:\TEST\IN
set targetDir=C:\TEST\OUT
for %%a IN (%sourceDir%\*.*) do (
@echo on
C:\TEST\zpki1utl -encrypt -in %%a -out %targetDir%\%%~na.p7e -recsubj "cn=m00225"
@echo off
)

bredych 06-03-2018 12:43 2801910

Цитата:

Цитата s-urbanas
\%%~na.p7e »

может быть правильнее %%~nxa ?
потому что eXtension вы в оригинале не берете.

s-urbanas 06-03-2018 12:53 2801915

bredych,

Спасибо! Помогло!

А что значит %%~nxa - можете подробно описать?

Patroklos 06-03-2018 15:55 2801955

Как у вас с английским?
Если знаете то можете у себя в консоли набрать for /? и почитать.
Код:

C:\Users\ABC>for /?
Runs a specified command for each file in a set of files.

In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

    %~I        - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I  - searches the directories listed in the PATH
                  environment variable and expands %I to the
                  fully qualified name of the first one found.
                  If the environment variable name is not
                  defined or the file is not found by the
                  search, then this modifier expands to the
                  empty string

The modifiers can be combined to get compound results:

    %~dpI      - expands %I to a drive letter and path only
    %~nxI      - expands %I to a file name and extension only
    %~fsI      - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                  environment variable for %I and expands to the
                  drive letter and path of the first one found.
    %~ftzaI    - expands %I to a DIR like output line

In the above examples %I and PATH can be replaced by other valid
values.  The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.



Время: 23:02.

Время: 23:02.
© OSzone.net 2001-