By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,205 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,205 IT Pros & Developers. It's quick & easy.

Need a Windows Script Host VBScript File that Moves a Text File...

P: 1 a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem:

I need a Visual Basic Script file, call it "Move and Reformat Text File.VBS," that will run from a Windows Script Host command-prompt-based version as follows:

C:\> Cscript.exe "Move and Reformat Text File.VBS"

The objective of the VBScript file, "Move and Reformat Text File.VBS, is to move a text file from an input folder, "C:\Input\, to an output folder, "C:\Output\, but with all lines of the original file concatenated to a single string, and with a space inserted between the line elements.

For example, say, the input file is "C:\Input\1.TXT" and it contains the following lines:

. . .

Then I want to create a corresponding output file "C:\Output\1.txt" that contains a single line, i.e., one string, as follows:

Line_1 Line_2 . . . Line_n

Note the single space inserted between each line.

After this is done, delete the input file, "1.TXT " from the "C:\Input\" folder.

Do this procedure for each *.TXT file in the input folder.

Also, sense when a new text file is added to the "C:\Input\" folder and run the procedure again. Or, if it is not feasible to program that, then at least invoke "Move and Reformat Text File.VBS" periodically, say, every five minutes.

In summary, here is the pseudo code outline of the procedure I envision:

For each text file in the input folder
- Create a new, blank, output text file of the same name as the input file.
- Save the new output text file in the output folder.
- Concatenate all the lines of the input file to one string.
- Append the concatenated string in the new output text file.
- Close the output text file.
- Delete the input text file.

Thanks for your help.
Jan 4 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
This would be pretty simple to do in straight VB, but don't think I've ever written a VBS.

However, I think Windows Scheduled Tasks will provide the "run every five minutes" functionality if you need it. If this were straight VB6 code, I would either use a timer control to wake up every however-often and scan the directory for new files. You could also have the program do an infinite loop executing a DoEvents statement and watch the folder for new files. Probably better to keep an eye on the time, and only check periodically; you might slow other processes down if you keep hammering the directory a hundred times a second.
Jan 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.