Computing.Net > Forums > Disk Operating System > Batch Execute

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Execute

Reply to Message Icon

Name: egypt123
Date: November 11, 2003 at 16:47:29 Pacific
OS: Win2k
CPU/Ram: P4 1GHZ
Comment:

I'm totally oblivious to DOS batch programming so I hope somone can help me. What I have is an executable that can encrypt an individual file in a directory. What I pass to the executable is the folder\filename and output folder\filename.

Ex: encrypt.exe c:\myfolder\myfile.ext | c:\myfolder\myfile.ext

The encrypt executable takes the file "myfile.ext" and encrypts it to the same folder with the same name (myfile.ext). This works great if I only do it on an individual files basis. What I want to do is have a batch file that loops through the folder in these steps:

1. Indentifies the filename of each file in a folder (so I don't need to know what it is in advance) and sets that as a variable.

2. Loops through and executes the encrypt.exe on each file, while passing the filename variable as the output filename.

In a perfect world, I'd be able to enter the folder name that contains the files I want to encrypt from the command line, and even possibly tell it the file type (extension) I want to encrypt:

encrypt.bat c:\myfolder\

or

encrypt.bat c:\myfolder\*.ext

Thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: November 12, 2003 at 02:40:59 Pacific
Reply:

The following batch is what you want

@Echo Off

:: Encrp.bat Syntax Encrp Folder File_Extension
:: Folder is the folder to be processed
:: File_Ext the extension of fiules without the . (dot)
:: Use * to encrypt all files stored in the folder
:: Example: Encr C:\Myfolder\MySubFolder bat

Echo.
If %1.==. (Echo Folder missing & GoTo :EOF)
If not exist %1.\Nul (Echo Folder "%~f1" not found & GoTo :EOF)
If %2.==. (Echo Extension missing & GoTo :EOF)

Echo Encrypting Files *.%2 in Folder %~f1
Echo.
For /F "tokens=*" %%A in ('Dir /B /A:-D %1.\*.%2') Do (
Encrypt %~f1.\%%A %~f1.\%%A
Echo Encrypt %~f1.\%%A %~f1.\%%A)
Echo.
Echo Processing completed

How to use it is explained in the comment lines at the top of the code, anyway type Encrp C:\MyFoder\Sub1\Sub2 * to encrypt all files stored in C:\MyFolder\Sub1\Sub2 or use the extension you like. The folder name and files names must not contain blanks. Win NT/2K/XP required. I suggest you do NOT name the batch as your exe (Encrypt.exe).

If you need more support, post again.


0

Response Number 2
Name: IVO
Date: November 12, 2003 at 02:50:10 Pacific
Reply:

I do not fully understand the syntax of your Encrypt command. If it requires a pipe symbol between input and output operands replace my statement

Encrypt %~f1.\%%A %~f1.\%%A

with

Encrypt %~f1.\%%A | %~f1.\%%A


0

Response Number 3
Name: egypt123
Date: November 12, 2003 at 11:36:35 Pacific
Reply:

Thanks IVO. This works great on files located in the root folder, which is good enough for now. Couple of other "nice to haves", however, would be:

1. A way to recurse through (and run my utilitiy) on files located in subdirectories under the root.

2. A way to read each ASCII file prior to running the encryption utility to see if they contain a text string in them. If they do have the text string - run the encryption, if they don't - bypass the file (take no action on that file) and move to the next.

Anyway, thanks a bunch this works for now.


0

Response Number 4
Name: IVO
Date: November 13, 2003 at 06:34:26 Pacific
Reply:

Check your InBox for the improved version of the script you are waiting.


0

Response Number 5
Name: IVO
Date: November 14, 2003 at 07:26:31 Pacific
Reply:

The ultimate version with full sub folders processing is in your InBox.


0

Related Posts

See More



Response Number 6
Name: jayr0
Date: December 31, 2003 at 07:51:21 Pacific
Reply:

can you send me the encryption program?

Thx


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch Execute

batch execution of a single command www.computing.net/answers/dos/batch-execution-of-a-single-command/12953.html

Adding lines to registry from batch www.computing.net/answers/dos/adding-lines-to-registry-from-batch/7264.html

Can you execute a batch file for a web page www.computing.net/answers/dos/can-you-execute-a-batch-file-for-a-web-page-/5382.html