Saved Bookmarks
| 1. |
Solve : My Backup Script (Easy problem) [SOLVED]? |
|
Answer» It's not much right now, but it should be close to finnishing. I just ran into a problem where when I tried to backup a file, I only GET 1 line of text. This must be a really easy solution, I know that I know it, it's one of those tip of my tongue things. Here's the code. Backup which file? Include extension and path. but it doesnt happen all the TIME. i tried this next: Quote Backup which file? Include extension and path. dont know if thats supposed to happen or just a bug. but thats the bugs i found so far. Hope this HELPED ,Nick(macdad-) if the path has spaces the variable needs quotes... Code: [Select]set /p file= if not exist "%file%" echo File not found! & Pause & Cls & Goto loop set backup=<"%file%" echo %backup% FBQuote from: macdad- on December 30, 2008, 05:11:56 PM well found one error: That was something I just left out because I was doing stuff in the same directory anyway. But if you do add quotes, it will only echo the first line. Once someone tells me how to get it to read not just the first line, but the entire file, then it should be able to backup any type of file. Quote from: fireballs on December 30, 2008, 05:32:19 PM if the path has spaces the variable needs quotes...I assumed everyone knew that already...I think i know what you mean now, for DOS to 'read' a file use the type command: Code: [Select]set /p file= if not exist "%file%" echo File not found! & Pause & Cls & Goto loop type "%file%" FBQuote from: fireballs on December 31, 2008, 03:24:00 AM I think i know what you mean now, for DOS to 'read' a file use the type command:Quote No. That will DISPLAY the contents of the file. My intentions were to The premise to #1 is wrong. Any reason you cannot use the copy command to copy the file? Note: By requesting the user to enter path and extension, be aware that %file%.txt will resolve to a file name with multiple dots. Quote from: Sidewinder on January 01, 2009, 07:50:11 AM QuoteI mean SET %backup% to be the contents of the file. And for 2, I did that for a reason.QuoteNo. That will DISPLAY the contents of the file. My intentions were to I mean SET %backup% to be the contents of the file. And for 2, I did that for a reason. Redirection can copy a single line from a file into a variable, not the entire contents of the file. Concatenation will strip off the carriage returns/line feeds, resulting in an output file that is mis-aligned. Why can't you use copy? Note: Most Windows scripting languages have an instruction which can get the contents of a file into a variable. Have you considered VBScript as a solution?Quote from: Sidewinder on January 01, 2009, 09:43:51 AM QuoteI guess I could copy, then rename to a different extension, but I want to put more than one file into a single file.QuoteI mean SET %backup% to be the contents of the file. And for 2, I did that for a reason. I guess I could copy, then rename to a different extension, but I want to put more than one file into a single file. Based on your previous logic, you can use the type command: Code: [Select]type %file%.txt>>%file%.xyz Use two output redirection symbols to prevent overwriting the output file. Good luck. Note: files concatenated this way can be problematical to extract from the output file. Thanks. I didn't know that type could do that. |
|