Dos batch file error checking




















In use, go to the source directory and issue the CTTP command. Then go to the target directory and issue CFTP. All the files will have been transferred. If you are sure you don't need the TEMP directory copies, delete them. For some reason Microsoft changed the syntax to not allow switches for the "MOVE" command to be at the end of the line. Instead, they must directly follow the command. Don't forget to have a space between the command and any switches. Now rewrite all those files but substitute "Download" and "Upload" for "Temp".

You now have three clearing house directories. If you do both to and from, use both copy and move, and use all three directories, a total of twelve batch files will result. I have this set up in combination with many direct-access batch files for my most used directories. Thus, with one command I access the directory of choice, then issue another command to move or copy the files to one of the "clearing house" directories. A third command takes me to the target directory and the final command moves or copies the files from the clearing directory to the target directory.

Since they are being moved, you don't need to worry about saving any additional copies, so RAM drive reboot losses are not a factor unless power was to be lost during the operation.

It can often be finished before something like Windoze Extorturer can even be opened! UPDATE: Since I first wrote the clearing house batch files, I composed a batch file that allows direct copy or move operations and skips the "middle man" step.

It requires a change-directory program or batch-file shortcuts to the target directory in order to work. I use -Directory Maven for most of this purpose. This will make a zero-byte file which name will be in the format of "Year-Month-Day".

That keeps similar files in chronological order. You may then load it into an editor and add text. Here's a version that does both:. It is assumed here that it too, is in the "DOS" directory. Get that program at the XSET website. Here's a way to rename an existing file with the current date. Want to make a directory with the current date as its name?

This renames a directory with the current date as its name. Here's the scenario: Your hard drive is running low on room and you can't afford, or don't want to bother getting, a new one. You'd like to keep some files in a compressed archive but hate the idea of having to uncompress a given file to edit it, and then having to restore an updated version back into the compressed archive.

This batch file will allow you to retrieve a document from a. The example will be geared for plain text files, but you may substitute a word processor so that this batch file could retrieve, say a WordPerfect file, load it into that program, and then return it to the. You may also use the second version of this batch file as a simple viewer for files in that. Any text editor will work provided you can specify a file to load right from the command line. Be aware, any file you load with this setup must be in the.

Alternatively, you could write a series of these batch files, each for a specific. It will be also be assumed that your documents are archived in DOCS. First, the batch file checks to make sure you typed a file name at the command line. Next, it moves you to this directory for the editing job. It does ask before doing so, but this is an unnecessary step.

Editing within an empty directory prevents this step. Next, the file is expanded retrieved from the archive and loaded into EDIT. Note the " -m- " switch. This moves the expanded file into the zip archive, effectively removing it from the directory.

This is to prevent expanded files from cluttering the directory and taking up space should you forget to delete it after editing. Here, this deletion is taken care of for you. Be sure that switch is in lower case. The trailing minus sign is there to prevent PKZIP from deleting the directory should it be empty after the file is moved. In actuality, the directory should be empty because it is only supposed to be used as a temporary editing location.

Now what happens if you mistype the file name or you don't remember the name? Here's an improved version that will take that into consideration:. In this version, if no file name is typed at the command line, DOCS. If you wish to edit one of the files, you may then run the batch file again and add one of the file names at the command line. Then a message is displayed and the batch file ends.

After a successful edit, the contents of DOCS. It would be handy that if when you type a name that does not exist, you had the option to create that file and add it to the. This means that you would not have to add it manually and also means that this one batch file can now serve a triple purpose. These purposes are to be able to view the DOCS. If it finds it, the file is extracted, edited, and reinserted into the archive as before.

If that option is selected, the file is created and then added to DOCS. As a bonus, if the DOCS. As before, the contents of DOCS. It is not perfect because there are other ways to recover the file. However, the casual snoop will not be able to view or recover the deleted file's contents.

Ignore the opening "IF" statement for a moment. Next are displayed up to nine of the files you have selected for expunging. You may type more names, but only the first nine appear on the screen. It then asks if you want to continue. There, the DOS "REM" Remark command is used to create a new file with no information in it, but using the same name as the one you typed at the command line.

This overwrites your file's name with this new one, which incidently contains no information. That is, it is zero bytes in size. Then, this new file is deleted. This little batch can connect to your FTP server and logs you in before it gives you the prompt.

You can easily add more FTP commands to it, like changing directories or switching to binary mode or whatever you like to be done before taking over control on the FTP prompt. The FTP connection information is embedded within the batch itself. Optionally a FTP script can be provided as input stream, that way multiple FTP scripts can share the same login information. Example: FtpLogin. First time it retrieves a list of files on the FTP server.

The files in the trimmed list are then downloaded during a second connection. Title Connecting Title Preparing Title Processing Title Disconnecting All variables in the FTP script will be resolved. All batch lines start with semicolon so that they will be ignored by the FOR loop. Script: 1. Add this line at the beginning of the FTP script:. The "FTP -s:ftpscript. Good: You end up with only one file that contains the batch script and the FTP script combined. Minor flaw: The batch command in the first line causes an "Invalid command.

That way if the username, password or hostname for the FTP connection changes you only need to edit a single place instead of having to edit all FTP scripts one by one. This automatic login script also described in detail earlier can be used to execute different FTP scripts that share the same login information stored within the batch file.

This is no different from regularly executing FTP with -s option. Script: Download: FtpLoginSharing. The following batch script executes itself in SQL context. The trick is the GOTO command in the first line of the script. The batch script will then run the OSQL. In fact the file can be opened and executed in Query Analyzer as is, since the batch script in the file looks like a comment to the query language processor. Now we can embed SQL queries into a batch file. But how can we pass arguments from the batch script into SQL?

This can be done using a temporary table. Windows 10 this may not suffice, though, because errorlevels can have negative integer values as well. Specifies to exit the current batch script instead of CMD. If executed from outside a batch script, it will quit CMD. Specifies a numeric number. If quitting CMD. Viewed k times. Basically if any thing goes wrong I want to stop and print out what went wrong. Can anyone give me any pointers? Improve this question. John Saunders k 25 25 gold badges silver badges bronze badges.

Add a comment. Active Oldest Votes. Improve this answer. Community Bot 1 1 1 silver badge. Would u mind to provide a simple example with copy or del commands, pls? I tried it with del but it always outputs that it was successful even though the file was not there — xeruf.

However, it does print an error message to stderr if the delete fails. I have done the same thing for avoiding the automatic exit of cmd. Show 1 more comment. Invalid File error in Myexe. At first view, I did not get that one.



0コメント

  • 1000 / 1000