This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 2751. |
Solve : "set" not working as expected within a for loop? |
|
Answer» Okay, this is driving me batty. Can someone tell me what I'm doing wrong here, because I don't see it. Especially since I bounce around between Windows batch, linux shell, python, perl, etc. I Googled "delayed expansion" just to check that it brought up relevant stuff and I found a blog by someone called Batcheero, who explains it quite clearly, and he ALSO shows how to make a mixed batch/perl script Quote Perl In Batch Clothing quite a few tips http://batcheero.blogspot.com/ Yeah, that's the one I ended up at when I searched.Quote from: Dias de verano on January 29, 2009, 11:46:31 AM I re-read my answer and it kind of looks like I was calling you a noob, which wasn't very polite, and it wasn't my intention to be rude, so sorry if it sounded that way. You feeling all right Dias? FB |
|
| 2752. |
Solve : Hello! Very puzzling batch file execution, and need help!? |
|
Answer» Hi all, |
|
| 2753. |
Solve : Help With MS-DOS Please? |
|
Answer» I'm Having a problem With my MS-DOS Program\~Tmpa. I rebooted my COMPUTER and several popups come up on the screen and the only optoin that is given is to ignore or cancel. There is about Five To Six Popup windows the show up every 20 to 25 min. I fact they just poped up right now the hole window states from top left. |
|
| 2754. |
Solve : a batch program to create directory with the name yyyymmdd? |
|
Answer» I am using the following SCRIPT but it does not PRODUCE yyyymmdd only yyyyddmm Echo mkdir %YYYYMMDD%%HHMM% That's your problem. Change it to Quote Echo mkdir %YYYDDMM%%HHMM% |
|
| 2755. |
Solve : file convertion.....? |
|
Answer» I am new to the DOS world, and I have a question. Is there an application that convers an .exe back to a .bat or something that you can see the codes? I am creating a batch FILE to auto run an application but it's not working correctly due to the fact that the application also call for some other executables. I want to see the codes so that I can include those executables in my batch. Can someone help? ThanksI HEARD that some bat to exe wrappers for batch FILES if you change the .exe to .bat and then use the EDITOR they are raw ascii ... havent confirmed this, but I overheard sort of speak some info on this on the web with one of the free batch to exe wrappers. Give it a try and see. |
|
| 2756. |
Solve : command for including dimensions when printing directory? |
|
Answer» I would like to be able to print a list of a file containing pictures to a text file and have that list include the DIMENSIONS of the file as can be displayed in windows explorer. My computer is Windows XP. |
|
| 2757. |
Solve : find command? |
|
Answer» I WANT to find a string in file and PROMPT message if the count is >0. check the errorlevel, i think this is the right way round: but... Quote how to capture number of occurance in script??? But... Quote from: rao on January 29, 2009, 08:13:59 AM I want to find a string in file and prompt message if the count is >0. I read the original POST as MEANING the above, and capturing the occurances as an after thought to stop the output appearing on screen. I guess the OP can clear this up. FBYup you're right, the OP asked 2 different questions. By the way in Windows 200 and later these work Code: [Select]find "Hello" "C:\test.dat">nul && echo hello is present in the file Code: [Select]find "Hello" "C:\test.dat">nul || echo hello is not present in the file to get the count is slightly more complex and the OP should please say if that is what he or she wants. |
|
| 2758. |
Solve : Need a bit of help? |
|
Answer» Hi all, |
|
| 2759. |
Solve : Running a batch file from a different directory? |
|
Answer» Hello, Hello, Use the complete path to configurewebserver_1.bat regardless which folder you are in: C:\Program Files\IBM\WebSphere\AppServer\bin\configurewebserver_1.bat or copy configurewebserver_1.bat to the new folder and then execute. |
|
| 2760. |
Solve : Missing files? |
|
Answer» When the COMPUTER says that The following file is missing or CORRUPTED, How do I fix it?It all rather DEPENDS on which file it is ... simplistic answer is to put the in the correct PLACE |
|
| 2761. |
Solve : How to get the command result?? |
|
Answer» Salaam, |
|
| 2762. |
Solve : Make a batch file click the mouse? |
|
Answer» OK well how do i make a BATCH file click the mouse rapidly for the use of css because my Friend bought a mouse with like turbo and all it does it when you PRESS the left mouse button and a button on the side it click rapidly. but he wont stop rubbing it in my face because you can shoot faster in the game. so if anyone knows how i can do this in a batch file by pressing ctrl + to turn on on ctrl - to turn off please help or i will keep dieing when hes over and if you cant do it with a batch file what can you do it with and how? |
|
| 2763. |
Solve : ESC give a certain errorlevel ?? |
|
Answer» My main question is. When you use escape to exit a program or SOMETHING. Would that give off a certain ERRORLEVEL? Or would it give of an errorlevel similar to other ones. My second question is. Is it possible to clear variables, so that they can be set again.Quote My second question is. Is it possible to clear variables, so that they can be set again. You don't need to, simply give your variable a new value. You can also use set var=, just as you would at the console. You can also reset variables by using setlocal and endlocal in tandem, by restricting the scope of each variable. Quote When you use escape to exit a program or something. Would that give off a certain errorlevel? It should. I believe they are called scan codes. If you need it, I may have a little DOS script that will produce an errorlevel value for every key. That would be great if I had that script. Then a user wouldn't have to press enter to choose an option in a batch file menu .The script is older than dirt. It might even still work. Code: [Select]A 100 XOR AH, AH INT 16 CMP AH, 0 JE 100 MOV AL, AH MOV AH,4C INT 21 R CX 10 N SCANCODE.COM W Q The last line is purposely left blank. Save the script with a scr extension and from the command line run debug < scriptname.scr to assemble the code. The ASSEMBLED program is scancode.com. The batch file returns the scancode of the key pressed at the prompt. Code: [Select]@echo off echo Enter Key: scancode echo %errorlevel% Good luck. . It didn't work..Quote It didn't work.. That response is right up there with there is weather outside. How did it not work? When you ran the batch file did you get a prompt? What key did you RESPOND with? What happened next? Did you copy/paste the script? Did you type it out yourself? Maybe it doesn't work on Vista. Works OK with XP. Maybe this should have been left in the grave of DOS 3.1 Well, I copy and pasted it into notepad, (I added the blankspace). Then I did from the command line that debug < scriptname.scr, and it said something like it can't find the file.Quote from: BatchFileCommand on January 27, 2009, 06:37:16 PM Well, I copy and pasted it into notepad, (I added the blankspace). Then I did from the command line that Did you save it with the name scriptname.scr in the right folder? Quote something like Love the precision. in Vista there is no DEBUG That explains that then.I use Vista home premium and i've got debug, and i've just tested the code from Sidewinder and it works fine. FBweird- it's not on my Vista Ultimate I have on my laptop- is it a separate checkbox during the installation? Or maybe you copied it after install FB?OEM installation, and i don't believe i've downloaded it since installation. THOUGH i've got telnet and that's 'hidden' in vista too. It might be something like that with debug. FBif they didn't include debug that would have been dumb. "hey, let's remove that silly debug tool! And while we're at it let's give everybody that useless edlin tool from DOS 5!" I did a dir /s and debug.exe wasn't found on my vista install- so I took the cheap way out and copied it from my XP x64 partition. Not that I ever use debug, though. But on the other hand, I never use my XP installs since they have a few issues I am too lazy to address either...I have Vista Ultimate too. Debuggers not in the extra features either. |
|
| 2764. |
Solve : Help Please (not recognized internal...)? |
|
Answer» Hey, i need some help. start a command window, at the prompt type c:\WINDOWS\system32ok i figured out what the problem was.. the default "path" isnt in the system32, how can i set the path internally? so i dont have to set it each time i open cmd.1 Right click My Computer and click properties. 2 In the System Properties window, click on the Advanced tab. 3 In the Advanced section, click the Environment Variables button. 4 In the Environment Variables window, highlight the path variable in the Systems Variable section and click edit. This is the default Windows XP path variable: C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem If you need to add any more folders, they can be added, SEPARATED by semicolons as above. 5 Click OK twice. 6 Reboot Question I have is what does PING have to do with C++? Are you trying to perform a system(" "); call in C++ that PINGs? Hoping this is a friendly console app you are attempting to create and not malicious! Quote from: DaveLembke on January 28, 2009, 01:13:22 PM Question I have is what does PING have to do with C++? Nope i was playing around with C ++ and thats how i figured out something was wrong with my cmd.. so i tryed a simple PING to see if i was right... Everythings working now tho, thanks for the help Ok then... btw you can use SYSTEM(" "); to execute other executables and dos commands from within your C++ program by placing a path to the executable or dos command in between the " " .... the C++ Express should have the .h handlers automatic, older VC++ 6 etc you had to manually #include the handler at the top of the program. Just in case you wanted to know that ... or the more versatile WinExec or ShellExecute, ShellExecuteEx, or CreateProcess routines that can be imported via the windows headers. |
|
| 2765. |
Solve : Windows Updates - System Restart - Can dos tell?? |
|
Answer» I have some systems that patch over the weekend and restart at around 3 am Monday morning. Some of the systems are considered servers and have processes that run on that are required to be up and running prior to other systems COMING online, if they come up in the wrong order then applications on other machine with fail to work correctly until the app is terminated and the services are restarted. |
|
| 2766. |
Solve : Is it possible to convert the binary file to ASCII file?? |
|
Answer» Hi Friend, I need a CODE to convert the file from Binary to ASCII formated file.... I dont want any tools to do it..., that doesn't MAKE any sense. Binary isn't a file format- it's a method of creating a file format. Word documents are binary. so are EXE images. So are a number of other formats... what kind of "Binary file" are you trying to convert to ASCII and what possible information could you glean from the ASCII result? If your looking to turn it into ASCII via HEX, a simple application to do so would load the file and write out the HEX equivalent of each byte. if your looking for CODE you should probably SPECIFY what kind of CODE you want. There is more then one type of CODE to do it in, and capitalizing CODE provides no benefit grammatically as I have just discovered. EDIT: ALSO, we aren't here to do what might be homework for you; especially when the description is exceptionally vague.well its pretty hard to do it in batch. you would need to learn binary and how to convert from binary to 32bit Integer and then convert that to its ASCII equivalent. VB would be needed for this kinda thing, since there are no user defined data types in batch.Quote from: macdad- on January 28, 2009, 05:45:21 AM VB would be needed for this kinda thing, since there are no user defined data types in batch. you wouldn't need a UDT. Code: [Select]Private Function GetHiWord(dw As Long) As Integer If dw& And &H80000000 Then GetHiWord% = (dw& \ 65535) - 1 Else GetHiWord% = dw& \ 65535 End If End Function Private Function GetLoWord(dw As Long) As Integer If dw& And &H8000& Then GetLoWord% = &H8000 Or (dw& And &H7FFF&) Else GetLoWord% = dw& And &HFFFF& End If End Function Public Sub Binfile2Hexfile(ByVal InFile As String, ByVal Outfile As String) 'Input: Any file. 'Output: will create a file with each byte of Infile represented as a hexadecimal number. 'Each byte is separated by a colon. 'each line will contain 10 bytes worth of hex data. Dim fnIn As Integer, fnout As Integer 'open both files. Dim longval As Long, longStr As String Dim tmpInt(1 To 2) As Integer, HexStr As String Dim AddColonCounter As Integer, BytesOnline As Integer fnIn = FreeFile Open InFile For Binary As fnIn fnout = FreeFile Open Outfile For Output As fnout Do Until EOF(fnIn) Get #fnIn, , longval longStr = "" 'convert to a Hexadecimal string. Add necessary zeros to make it the proper size- ' in the case of a VB6 long variable, it's 8 bytes binary, but each byte is 2 bytes hex, so 16 characters. HexStr = Hex(longval) 'Debug.Assert longval = 0 If longval > 0 Then longStr = String$(8 - Len(HexStr), "0") + Trim$(HexStr) Else longStr = String$(8, "0") End If For AddColonCounter = 1 To 2 Mid$(longStr, (AddColonCounter * 2) + (AddColonCounter), 1) = ":" Next AddColonCounter Print #fnout, longStr; BytesOnline = BytesOnline + 1 If BytesOnline = 10 Then Print #fnout, vbCrLf BytesOnline = 0 End If Loop Close #fnout Close #fnIn End Sub *censored*, sometimes I forget all the experience I have with string manip routines. Haven't used the statement form of mid$ for a very long time... nicely done BC! kept getting errors with mine. took about 30 minutes. I was about to use a UDT and I realized that's what I was disproving So I just had to add in the low-word/hi-word functions, which I ended up not using anyway. interesting. |
|
| 2767. |
Solve : how would i cheak to see if a file exsists?? |
|
Answer» how WOULD i cheak to see if a file exsists? unfortunatly i dont know what it changes to The you are stuck unless you do it manually. ok there is a shortcut on my desktop and its link goes straght to the folder how would i save that link as a variable?SET linkvariable=shorcut.lnk |
|
| 2768. |
Solve : Elevated command prompt faiis to find path? |
|
Answer» Hi |
|
| 2769. |
Solve : how can i rar windows folder in dos? |
|
Answer» hi doesn't work You are not meant to copy the < and > symbols; they are there to show that what is between them is an example. It's also probably not a good way to backup Windows anyways...Quote from: patio on June 03, 2010, 12:42:54 PM It's also probably not a good way to backup Windows anyways... Command line RAR or WinRAR, same problems. No good for BACKING up Windows. then which way is good? TRUE image doesn't supplies me i WANT to make backup so if someday i will want to format and reinstall windows i can do it by image iso or something and it will be exatcly like now with all the programs installedQuote from: punto on June 03, 2010, 03:59:29 PM then which way is good? yeah... and trueimage, despite being designed for that very purpose, doesn't cut it?probably no keeps giving me errorsQuote from: punto on June 03, 2010, 09:23:33 PM probably no Feel free to tell us what these errors are.Quote backup to windows folder by raring it Are You Serious About That... Means How COULD You.....Why Do You....What Is The Use Of It |
|
| 2770. |
Solve : How can i move files in directories without the directories?? |
|
Answer» look here just that this command move only the files inside the directories and leaving the direcories emptyanyone?ignore the phrase "backup". It just means "COPY". Quote Have you got permission of the copyright owners of Prison Break to download their show? Salmon..... Alwayz Following Rules ,Copyright, Law And Order Salute To Your Rules Following NatureQuote from: the_mad_joker on June 04, 2010, 02:33:26 AM Salmon..... Alwayz Following Rules ,Copyright, Law And Order No. But he understands the adage that when in Rome, you do as the Romans do. Or, when you're on a forum you follow the rules. It's really quite a simple premise. I'm rather surprised it so easily slips out of the clutches of the cognitive skills of so many people seeking assistance.Quote Rome, you do as the Romans do. This Time I Am Not Joking... But Seriously Dude NICE EXAMPLE mad joker, you do post like a complete jerkwad sometimes. Most of the time in FACT. Maybe EVEN all of the time. |
|
| 2771. |
Solve : bat file... quick launch icon!? |
|
Answer» what is the code for CREATING a quick launch icon to my .exeQuote what is the code for creating a quick launch icon to my .exe Quick Launch Means Shortcut Or .... Quote from: night-rider on June 03, 2010, 11:13:34 PM what is the code for creating a quick launch icon to my .exe C:\test>type coll.bat @ECHO off start "c:\program files\internet explorer\iexplore.exe" HTTP://www.google.com/ C:\test>what did that do Marvin Quote from: the_mad_joker on June 04, 2010, 02:34:17 AM Quick Launch Means Shortcut Or .... yap! so maybe I will just then copy the shortcut icon to the DIRECTORY of quicklaunch.Quote from: mat123 on June 04, 2010, 05:53:32 PM what did that do Marvin Starts internet Explorer and displays google.com. relevance is left as an exercise for the reader, I suppose. |
|
| 2772. |
Solve : serch bat program? |
|
Answer» Quote from: mat123 on June 03, 2010, 08:03:54 AM Marvin bat to exe compilers have a bat FILE in them The reason to complie a batch file to an .exe file is to hide the batch code? But now you say the .exe file can be edited with your decomplier and the original batch code is available. I doubt it. Please show your output. Quote from: mat123 on June 03, 2010, 08:03:54 AM Marvin bat to exe compilers have a bat file in them Sometimes it is run from memoryQuote from: Salmon Trout on June 03, 2010, 11:27:50 AM Sometimes it is run from memoryIt all depends on what converter you used.Quote from: Helpmeh on June 03, 2010, 03:28:17 PM It all depends on what converter you used. Does Helmeh mean the compiler that changed the original batch file to an exe file? Or does Helpmeh mean the "DECompiler" that changes the exe file to the original batch file?Quote from: marvinengland on June 03, 2010, 04:13:57 PM Does Helmeh mean the compiler that changed the original batch file to an exe file?Try reading. If you do, you may realize that neither of those options are what I mean.Quote from: mat123 on May 23, 2010, 04:42:01 PM I am making a exe to bat decompliler but it has problems could you help me fix them http://technet.microsoft.com/en-us/library/cc750056.aspx All the following from the above link. "Compiling Batch Files Batch Files are easy to modify, which can create problems. BAT2EXEC is a compiler for batch files, and it turns your batch file into a exe file. Compiled batch files execute faster and create a source code that is protected from change. Before you compile a batch file, be sure to save the original under another name. Once you have compiled the file using BAT2EXEC, you cannot uncompile it to make changes."Quote from: marvinengland on June 03, 2010, 06:47:31 PM try using bat2exec on a batch file today. Note the DATE: "BAT2EXEC (Douglas Boling, PC Magazine, August 1990)" How many batch files posted here would work on DOS 6? a optimistic estimate would be mybe a quarter of a percent. It only works for batch files that work in Pure DOS- that is, no for /f, no FORFILES, no command extensions whatsoever. You'd be hard pressed to find more then a handful of batch files that will actually work with that compiler today. Additionally since the result is also a DOS COM executable it won't work on 64-bit operating systems and doesn't support anything provided by cmd- including long file names. Additionally the number of additional limitations imposed on the function of a batch file when it is converted to a 64K flat model restrict it's usefulness even further. Good luck creating something useful within such severe limitations. In fact, even the relatively simple batch file you posted earlier wouldn't work: Code: [Select]@echo off rem Convert exe to bat rem http://fixunix.com/ms-dos/539963-converting-exe-file-bat-file.html rem How to convert exe file to bat file? Rem Simple, here's an example: @echo off REM tested ren myfile.exe myfile.bat rem another example: echo off REM RESULTS cause problems in some OS's ren Buddist.exe Christian.bat Know why? Of course not. That's why you think bat2exec is even close to what is being discussed. If you add a "dir Christian.bat" to the end of that batch (in order to confirm output, as you are so readily able to point out in other peoples batches but appear to neglect in your own) you will get the message "File not found". If even the most basic batch consisting of a few rename commands doesn't work properly what hope is there for batches that actually do something useful? Quote from: marvinengland on June 03, 2010, 06:47:31 PM
I did not write the following code. I provided a link to the code. The code demonstrated the futility of a "decompiler." The code and link did not claim a valid decompiler. rem Convert exe to bat http://fixunix.com/ms-dos/539963-converting-exe-file-bat-file.html How to convert exe file to bat file? Simple, here's an example: Code: [Select]@echo off REM tested ren myfile.exe myfile.bat rem another example: echo off REM results cause problems in some OS's ren Buddist.exe Christian.bathttp://www.program-transformation.org/Transform/LegalityOfDecompilation Legality Of Decompilation Program-Transformation.Org: The Program Transformation WikiIf decompilation is possible to a certain extent, is it then also allowed? Decompilation can be used for a number of reasons (see WhyDecompilation for more), including: Recovery of lost source code (by accident or via a disgruntled employee), Migration of assembly language applications to a new hardware platform, Translation of code written in obsolete languages no longer supported by compiler TOOLS, Determination of the existence of viruses or malicious code in the program, and Recovery of someone else's source code (to determine an algorithm for example). However, not all uses of decompilers are legal uses. Throughout the world, computer programs are protected by copyright law. Copyright protects the expression of an idea in the form of a program, hence protecting the developer's (or company's) investment in writing the software. Copyright law provides a bundle of exclusive rights to the software developer; among others, the right to reproduce and make adaptations to the developed computer program. It is a breach of these rights to make reproductions or adaptations without permission of the copyright holder. Further, license agreements may also bind the user to operate the program in a certain way and to avoid using decompilation or disassembly techniques on that program. Different countries have different exceptions to the copyright owner's rights or precedent has been established in court proceedings. This means that these uses are allowed by law. The most common ones are: Decompilation/disassembly for the purposes of interoperability (to another piece of software or hardware) where the interface specification has not been made available, Decompilation/disassembly for the purposes of error correction where the owner of the copyright is not available to make the correction, and To determine parts of the program that are not protected by copyright (e.g. algorithms), without breach of other forms of protection (e.g. patents or trade secrets). Not all countries implement the same laws, you should contact your lawyer if in doubt. |
|
| 2773. |
Solve : how can i stop the scandisk? |
|
Answer» hi |
|
| 2774. |
Solve : Robocopy version and Download source? |
|
Answer» Hi, Hi, C:\>dir /s robo*.* Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of C:\Program Files\Windows Resource Kits\Tools 04/02/2003 08:07 PM 253,440 robocopy.doc 04/18/2003 06:06 PM 79,872 robocopy.exe 2 File(s) 333,312 bytes http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en Directory of C:\Windows\System32 07/13/2009 08:14 PM 97,280 Robocopy.exe 1 File(s) 97,280 bytes Code: [Select]Version File version Year Origin 1.70 - 1997 Windows NT Resource Kit 1.71 4.0.1.71 1997 Windows NT Resource Kit 1.95 4.0.1.95 1999 Windows 2000 Resource Kit 1.96 4.0.1.96 1999 Windows 2000 Resource Kit XP010 5.1.1.1010 2003 Windows 2003 Resource Kit XP026 5.1.2600.26 2005 Downloaded with Robocopy GUI v.3.1.2 XP027 5.1.10.1027 2008 Bundled with Windows Vista, Server 2008 and later Note: XP027 only runs on Vista and later, and was included in those OSs anyway, so there is no point in downloading later than XP026. Holey Cow...Thanks to all for the responses. My Win Vista has Windows Resource Kits Tools is here: C:\Program Files (x86)\Windows Resource Kits\Tools It has Subinacl but I don't see Robocopy. The reason that I asked about the version of Robocopy is because I got in considerable difficulty with some folders and files regarding ownership and permissions on the external drive that was used for backup by Robocopy. See Post "Elevated command Prompt fails to find path" Reply #4 on: June 01, 2010, 11:36:21 AM » I did not want to repeat that experience so I wanted to see if My robocopy was up to date. I did run it again and had no difficulty. Still, it would be nice to find the Robocopy.exe and see it's version number. Do you KNOW where it is in Vista Ultimate 64 bit? Thanks Frank CampQuote Do you know where it is in Vista Ultimate 64 bit? The usual place would be C:\Windows\System32 (This is where Robocopy.exe is on my Windows 7 Pro 64 bit, and I have no doubt that it's the same on Vista. If it is, and you didn't put it there, it must be the default bundled version and it must therefore be the latest version - XP027, file version 5.1.10.1027. Your file ownership/permission problems are unlikely to be have been CAUSED by Robocopy. Thanks so much Salmon Trout, I did find Robocopy.exe in C:\Windows\System32 It came bundled with Vista Ultimate 64 bit. It is version 5.1.0.0 1027 dated 1/20/2008. I do believe the ownership/permission problem arose from Robocopy. I was not using any other tool to write to the external drive. The bad owners were - nobody (Unix User\nobody) The OK owners were - Linux User,,, (EXTERNALDRIVE\everyone) Thanks Frank CampQuote I do believe the ownership/permission problem arose from Robocopy. I was not using any other tool to write to the external drive. Quote /COPY:copyflag :: what to COPY for files (default is /COPY:DAT). did you use /COPY:DATSOU ?Quote from: FrankGC on June 07, 2010, 03:28:23 PM I do believe the ownership/permission problem arose from Robocopy. I was not using any other tool to write to the external drive. OK, I'll rephrase it slightly Your file ownership/permission problems are likely to be have been caused by how you used Robocopy.Thanks to both for the response. This is the Robocpy cmd inside of a small .bat file Perhaps using /COPY:DT was not a good idea, but initially I got a lot of "Error 5 Access denied". Robocopy C:\Users\Owner\Music\recordings\ \\externaldrive\public\BackUp-Music\recordings\ /S /COPY:DT /MIR /Log:MusicBkupLog.txt /COPY:DT copies Data and Timestamps. Does not copy Attributes thus avoiding "Error 5 access denied". /MIR mirrors the source directory tree /S copy Subdirectories, but not empty ones. Running Robocopy under Task Scheduler can be challenging if the destination is a shared network drive. A solution to get the destination drive accessed is to use Universal Naming Convention (UNC) addressing for the target: \\externaldrive\public\BackUp-Music\recordings\ I used the same format to backup pictures with no problem: Robocopy C:\Users\Public\Pictures\ \\externaldrive\public\BackUp-Pictures\ /S /COPY:DT /MIR /Log:PictureBkupLog.txt Thanks Frank Camp |
|
| 2775. |
Solve : SORT.exe? |
|
Answer» Quote Run Command Window as System Administrator: This Worked For Me Hoorayyyyyyyyyyyyyy Quote from: the_mad_joker on June 08, 2010, 11:47:41 AM
Run Command Window as System Administrator: Click Start , right click Command Prompt and Choose "Run as System Administrator" The above worked because the default command window location for the System Administrator is : C:\Windows\system32\ When the OS searches for sort.exe, it looks at the current folder first. Nevertheless, for future sessions you need to set your system search PATH. C:\test>path PATH=C:\Program Files\Windows Resource Kits\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1 ;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\GnuWin32\bin;c:\bin C:\test>TYPE pat.bat @echo off set PATH=C:\Program Files\Windows Resource Kits\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShel 1.0\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\GnuWin32\bin;c:\bin rem path=%PATH%;C:\Program Files\GnuWin32\bin path C:\test>I've already told him that, marvin. Are you always going to dog my steps, posting the same things I do? I Think Salmon Is Angry On Marvin ...... LADIES AND GENTLEMAN ,Dogs And Cats ,Clowns (Of Course) We Are Gonna Have A FIGHT Here Common Salmon YOU Can Do It ======================================== | Apart Jokes , Thanx To Both Of You Salmon And Marvin | ======================================== |
|
| 2776. |
Solve : DOS command to Count files in a folder? |
|
Answer» Please help me with a DOS command to count the NUMBER of files in a FOLDER with name starting with 'xxx'. The folder contains hundreds of files and few of then will be of name 'xxx_01.txt', 'xxx_02.txt' 'xxx_03.txt' etc.There are several ways to do this, amongst them are: |
|
| 2777. |
Solve : return in the same window? |
|
Answer» Hi everyone, |
|
| 2778. |
Solve : Download the most recent files from FTP? |
|
Answer» I am trying to create a batch file that will download the 5 most recent files from the FTP. The full file name will be unknown because they are generational files. The files will look like AAAA.AAAAAAAAA.daily.G0001, AAAA.AAAAAAAAA.daily.G0002, AAAA.AAAAAAAAA.daily.G0003 etc. |
|
| 2779. |
Solve : Need to create batch file with 10 sec interval between every 5 files transferred? |
|
Answer» I need to create a batch file that copies multiple files (huge # of files) from my xp desktop to a windows 2003 server.
This is rough idea what is needed. A COUNTER and sleep command. C:\test>type zz.bat Code: [Select]@Echo off setlocal enabledelayedexpansion set /a CNT=0 for /f "delims=" %%i in ('dir /s /b c:\*.txt') do ( set /a cnt=!cnt! + 1 echo cnt=!cnt! if !cnt! EQU 10 sleep 10 if !cnt! EQU 12 goto end xcopy /s %%i c:\zz\ ) :end Output: C:\test>zz.bat cnt=1 cnt=3 C:\06-07-2010\a1.txt 1 File(s) copied cnt=4 C:\06-07-2010\a2.txt 1 File(s) copied cnt=5 C:\06-07-2010\a3.txt 1 File(s) copied cnt=6 C:\06-07-2010\a4.txt 1 File(s) copied cnt=7 C:\06-07-2010\a5.txt 1 File(s) copied cnt=8 C:\06-07-2010\abc.txt C:\06-07-2010\archive\abc.txt C:\06-07-2010\Backup\15\abc.txt C:\06-07-2010\Backup\17\abc.txt C:\06-07-2010\Backup\18\abc.txt C:\06-07-2010\savhere\abc.txt 6 File(s) copied cnt=9 C:\06-07-2010\abc2.txt C:\06-07-2010\archive\abc2.txt C:\06-07-2010\Backup\15\abc2.txt C:\06-07-2010\Backup\17\abc2.txt C:\06-07-2010\Backup\18\abc2.txt C:\06-07-2010\savhere\abc2.txt 6 File(s) copied cnt=10 C:\06-07-2010\abc5.txt C:\06-07-2010\Backup\17\abc5.txt C:\06-07-2010\Backup\18\abc5.txt 3 File(s) copied cnt=11 C:\06-07-2010\arc.txt 1 File(s) copied cnt=12 C:\test>I have to SAY, not a bad effort by marvin. |
|
| 2780. |
Solve : MS Dos Project? |
|
Answer» The project I have to do is create a zip file in MS Doc for all data that fails. & Then plainly put the created code with the rest of the code. Please tell me if I am on the right track & please give me hints. Sorry that I commented my code the way I did. I am used to dealing with C++ Programming & Java. Basically the program/ code is supposed to place all failed data into a file, I want to put it into a zip file. I am trying to figure out how to create the code so that the failed data can transfer into the zip file efficiently. P.S. I am doing this my uncle; who owns technology company. since every line with a // is now invalid you can start by fixing the comments. use REM, not ::, by the way. :: has too many special cases where it can cause all sorts of problems.Okay I fixed the comment aspect. Whats next?? Fixed Code: ECHO OFF :: Displays messages, or turns command-echoing off. set ConfigFile=config.cfg :: Allows you to change one variable or string to another. set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt :: Allows you to change one variable or string to another. set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt :: Allows you to change one variable or string to another. set wmailto=c:\windows\wmailto.exe :: Allows you to change one variable or string to another. set "ExistFreeSpace=0" :: Allows you to change one variable or string to another. echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on date /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: Call to the file and displays. :: ** Call MDMcreateCSVfiles :: Call to the file and displays. :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: Keep file running after it returns :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof) :: Checks to see if file is there; if not display the following messages. :: *** Call the subroutine; :: Calls another batch file and then returns to current batch file to continue. :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig email email :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig Warningemail Warningemail :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig extension extension :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig MinFreeSpacePrcnt MinFreeSpace :: Calls another batch file and then returns to current batch file to continue. echo Log space on server.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace >> %loglocation% :: Calls another batch file and then returns to current batch file to continue. setlocal EnableDelayedExpansion :: Inserts strings into the command environment. The set values can be used later by programs. FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i :: Executable statement call :ReadConfig Source!ind! source :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig OlderThan!ind! olderthan ::Calls another batch file and then returns to current batch file to continue. echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% :: Displays messages, or turns command-echoing off/on. echo . >>%loglocation% :: Displays messages, or turns command-echoing off/on. ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% ::executable statement echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% ::Displays messages, or turns command-echoing off/on. echo Delete finished... >> %loglocation% :: Displays messages, or turns command-echoing off/on. echo. >>%loglocation% ) :: Displays messages, or turns command-echoing off/on. echo. :: Displays messages, or turns command-echoing off/on. echo All Deletes complete.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace>> %loglocation% :: Calls another batch file and then returns to current batch file to continue. date /t >> %loglocation% ::Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. echo >>%loglocation% :: Displays file. if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) :: Executable statement %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof ::Executable statements :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :: Executable statements :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION :: Allows you to change one variable or string to another. ::@SETLOCAL ENABLEEXTENSIONS :: Allows you to change one variable or string to another. @CLS // @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p // @SET /A TotalSpace=!TotalBytes:~0,-9! // Allows you to change one variable or string to another. @SET /A FreeSpace=!FreeBytes:~0,-10! // Allows you to change one variable or string to another. @SET /A TotalUsed=%TotalSpace% - %FreeSpace% // Allows you to change one variable or string to another. @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! // Allows you to change one variable or string to another. @SET /A PercentFree=100-!PercentUsed! // Allows you to change one variable or string to another. @ECHO Total space: %TotalSpace%GB // Displays messages @ECHO Free space: %FreeSpace%GB // Displays messages @ECHO Used space: %TotalUsed%GB // Displays messages @ECHO Percent Used: %PercentUsed%%% // Displays messages @ECHO Percent Free: %PercentFree%%% // Displays messages ::ENDLOCAL // ENDLOCAL &set "%~1=%PercentFree%" // goto :eof // First, most of the comments are still "//" second, they can only appear on a line by themselves. batch has no PROVISION for inline comments. I did it, whats next : ECHO OFF :: Displays messages, or turns command-echoing off. set ConfigFile=config.cfg :: Allows you to change one variable or string to another. set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt :: Allows you to change one variable or string to another. set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt :: Allows you to change one variable or string to another. set wmailto=c:\windows\wmailto.exe :: Allows you to change one variable or string to another. set "ExistFreeSpace=0" :: Allows you to change one variable or string to another. echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on date /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: Call to the file and displays. :: ** Call MDMcreateCSVfiles :: Call to the file and displays. :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: Keep file running after it returns :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof) :: Checks to see if file is there; if not display the following messages. :: *** Call the subroutine; :: Calls another batch file and then returns to current batch file to continue. :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig email email :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig Warningemail Warningemail :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig extension extension :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig MinFreeSpacePrcnt MinFreeSpace :: Calls another batch file and then returns to current batch file to continue. echo Log space on server.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace >> %loglocation% :: Calls another batch file and then returns to current batch file to continue. setlocal EnableDelayedExpansion :: Inserts strings into the command environment. The set values can be used later by programs. FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i :: Executable statement call :ReadConfig Source!ind! source :: Calls another batch file and then returns to current batch file to continue. call :ReadConfig OlderThan!ind! olderthan ::Calls another batch file and then returns to current batch file to continue. echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% :: Displays messages, or turns command-echoing off/on. echo . >>%loglocation% :: Displays messages, or turns command-echoing off/on. ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% ::executable statement echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% ::Displays messages, or turns command-echoing off/on. echo Delete finished... >> %loglocation% :: Displays messages, or turns command-echoing off/on. echo. >>%loglocation% ) :: Displays messages, or turns command-echoing off/on. echo. :: Displays messages, or turns command-echoing off/on. echo All Deletes complete.... >> %loglocation% :: Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace>> %loglocation% :: Calls another batch file and then returns to current batch file to continue. date /t >> %loglocation% ::Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it. echo >>%loglocation% :: Displays file. if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) :: Executable statement %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof ::Executable statements :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :: Executable statements :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION :: Allows you to change one variable or string to another. ::@SETLOCAL ENABLEEXTENSIONS :: Allows you to change one variable or string to another. @CLS :: @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p :: @SET /A TotalSpace=!TotalBytes:~0,-9! :: Allows you to change one variable or string to another. @SET /A FreeSpace=!FreeBytes:~0,-10! :: Allows you to change one variable or string to another. @SET /A TotalUsed=%TotalSpace% - %FreeSpace% :: Allows you to change one variable or string to another. @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! :: Allows you to change one variable or string to another. @SET /A PercentFree=100-!PercentUsed! :: Allows you to change one variable or string to another. @ECHO Total space: %TotalSpace%GB :: Displays messages @ECHO Free space: %FreeSpace%GB ::Displays messages @ECHO Used space: %TotalUsed%GB :: Displays messages @ECHO Percent Used: %PercentUsed%%% :: Displays messages @ECHO Percent Free: %PercentFree%%% :: Displays messages ::ENDLOCAL :: ENDLOCAL &set "%~1=%PercentFree%" :: goto :eof :: Just to make sure you get this through: Quote from: BC_Programmer on June 10, 2010, 08:21:18 AM batch has no provision for inline comments. So, echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on needs to become: echo Job starting.... >> %loglocation% rem Displays messages, or turns command-echoing on You have been told this already... don't use double colons ( for comments! Use rem or REM. Using a broken LABEL (that is what :: is) causes problems in parenthetical structures, is unsupported, deprecated and is FROWNED UPON. ECHO OFF REM Displays messages, or turns command-echoing off. set ConfigFile=config.cfg REM Allows you to change one variable or string to another. set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt REM Allows you to change one variable or string to another. set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt REM Allows you to change one variable or string to another. set wmailto=c:\windows\wmailto.exe REM Allows you to change one variable or string to another. set "ExistFreeSpace=0" REM Allows you to change one variable or string to another. echo Job starting.... >> %loglocation% REM Displays messages, or turns command-echoing on date /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% REM Call to the file and displays. :: ** Call MDMcreateCSVfiles REM Call to the file and displays. :: ** echo Returned from bat file call - continuing.... >> %loglocation% REM Keep file running after it returns :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof) REM Checks to see if file is there; if not display the following messages. :: *** Call the subroutine; REM Calls another batch file and then returns to current batch file to continue. :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig email email REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig Warningemail Warningemail REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig extension extension REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig MinFreeSpacePrcnt MinFreeSpace REM Calls another batch file and then returns to current batch file to continue. echo Log space on server.... >> %loglocation% REM Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace >> %loglocation% REM Calls another batch file and then returns to current batch file to continue. setlocal EnableDelayedExpansion REM Inserts strings into the command environment. The set values can be used later by programs. FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i REM Executable statement call :ReadConfig Source!ind! source REM Calls another batch file and then returns to current batch file to continue. call :ReadConfig OlderThan!ind! olderthan REMCalls another batch file and then returns to current batch file to continue. echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% REM Displays messages, or turns command-echoing off/on. echo . >>%loglocation% REM Displays messages, or turns command-echoing off/on. ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% REM executable statement echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% REM Displays messages, or turns command-echoing off/on. echo Delete finished... >> %loglocation% REM Displays messages, or turns command-echoing off/on. echo. >>%loglocation% ) REM Displays messages, or turns command-echoing off/on. echo. :: Displays messages, or turns command-echoing off/on. echo All Deletes complete.... >> %loglocation% REM Displays messages, or turns command-echoing off/on. call :FreeSpace ExistFreeSpace>> %loglocation% REM Calls another batch file and then returns to current batch file to continue. date /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. time /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it. echo >>%loglocation% REM Displays file. if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) REM Executable statement %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof REM Executable statements :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof REM Executable statements :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION REM Allows you to change one variable or string to another. ::@SETLOCAL ENABLEEXTENSIONS REM Allows you to change one variable or string to another. @CLS REM @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p REM @SET /A TotalSpace=!TotalBytes:~0,-9! REM Allows you to change one variable or string to another. @SET /A FreeSpace=!FreeBytes:~0,-10! REM Allows you to change one variable or string to another. @SET /A TotalUsed=%TotalSpace% - %FreeSpace% REM Allows you to change one variable or string to another. @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! REM Allows you to change one variable or string to another. @SET /A PercentFree=100-!PercentUsed! REM Allows you to change one variable or string to another. @ECHO Total space: %TotalSpace%GB REM Displays messages @ECHO Free space: %FreeSpace%GB REM Displays messages @ECHO Used space: %TotalUsed%GB REM Displays messages @ECHO Percent Used: %PercentUsed%%% REM Displays messages @ECHO Percent Free: %PercentFree%%% REM Displays messages ::ENDLOCAL :: ENDLOCAL &set "%~1=%PercentFree%" REM goto :eof REM Now can someone please tell me how to create a zip file using this code? Thanks! Quote set ConfigFile=config.cfg REM Allows you to change one variable or string to another. You have also been told that you can't have inline comments! Don't you read the answers? Your configfile variable is going to be "config.cfg REM Allows you to change one variable or string to another." All those CHARACTERS. What are all those lines starting :: ** ? You are not going the right way to get your batch file fixed. ECHO OFF set ConfigFile=config.cfg set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt set wmailto=c:\windows\wmailto.exe set "ExistFreeSpace=0" echo Job starting.... >> %loglocation% date /t >> %loglocation% time /t >> %loglocation% :: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: ** Call MDMcreateCSVfiles :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof ) :: *** Call the subroutine; :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo call :ReadConfig email email call :ReadConfig Warningemail Warningemail call :ReadConfig extension extension call :ReadConfig MinFreeSpacePrcnt MinFreeSpace echo Log space on server.... >> %loglocation% call :FreeSpace ExistFreeSpace >> %loglocation% setlocal EnableDelayedExpansion FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i call :ReadConfig Source!ind! source call :ReadConfig OlderThan!ind! olderthan echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation% cd %source% echo . >>%loglocation% ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% echo Delete finished... >> %loglocation% echo. >>%loglocation% ) echo. echo All Deletes complete.... >> %loglocation% call :FreeSpace ExistFreeSpace>> %loglocation% date /t >> %loglocation% time /t >> %loglocation% echo >>%loglocation% if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION ::@SETLOCAL ENABLEEXTENSIONS @CLS @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p @SET /A TotalSpace=!TotalBytes:~0,-9! @SET /A FreeSpace=!FreeBytes:~0,-10! @SET /A TotalUsed=%TotalSpace% - %FreeSpace% @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! @SET /A PercentFree=100-!PercentUsed! @ECHO Total space: %TotalSpace%GB @ECHO Free space: %FreeSpace%GB @ECHO Used space: %TotalUsed%GB @ECHO Percent Used: %PercentUsed%%% @ECHO Percent Free: %PercentFree%%% ::ENDLOCAL ENDLOCAL &set "%~1=%PercentFree%" goto :eof Here it is! Please help me correct this. Replace the Code: [Select]:: *** with Code: [Select]REM. Sorry Patio, just had to..He's now been told 3 times... methinks this is going to go nowhere... No problem MacDad... |
|
| 2781. |
Solve : MS Dos Bate File? |
|
Answer» These directories are only SET up on one test and one production server. We would like to have a job we can use to ALLOCATE these directories on a different server in case we would need to switch to a different server. Below is a list of the directories we would need. For each set of directories we would ALSO need the higher lever directory allocated, i.e.. For the MDMSPROJECT\PPL_BILL_REQUESTS\FAILED - LOADED - SQLLDR directories we would also have to have the MDMSPROJECT\PPL_BILL_REQUEST directory created first. |
|
| 2782. |
Solve : Help with bcdedit, Adding Startup from WIM file? |
|
Answer» Hello |
|
| 2783. |
Solve : Batch file to split a string into multiple strings? |
|
Answer» Hi. I need a script that will take a string and split it up by " %% " with no quotes. It would be very easy if you could output them on different lines (displayed). Thank you, but it just says "Echo is off". I ran this batch file... Code: [Select]@echo off echo MyString=wscript.arguments(0)>splitter.vbs echo MyArray = Split(MyString, "%%%%", -1, 1)>>splitter.vbs echo last=UBound(MyArray)>>splitter.vbs echo For j = 0 To last>>splitter.vbs echo wscript.echo MyArray(j)>>splitter.vbs echo Next>>splitter.vbs set Longstring=Cat%%%%Dog%%%%Horse%%%%Bird%%%%Fish%%%%Chicken echo Longstring=%Longstring% for /f "delims=" %%A in ( 'cscript //nologo splitter.vbs "%Longstring%" ' ) do echo %%A del splitter.vbs and this was the output... Code: [Select]Longstring=Cat%%Dog%%Horse%%Bird%%Fish%%Chicken Cat Dog Horse Bird Fish Chicken If you will show me the code you have used I will try to advise. Where are you getting the long string from? It changed on me. Now it is working. But one problem. I am getting the longstring from a file that I know exists (I entered the path in windows explorer) but it says the file is not found. Any ideas?Quote from: flytothemoon on June 11, 2010, 02:22:11 PM Any ideas? Be thorough and careful and check what you are doing. |
|
| 2784. |
Solve : Batch file write variables to file? |
|
Answer» Quote from: Linux711 on June 09, 2010, 07:21:57 PM The problem is that it does not write the variables to the file. It only partially works when I remove the whole if statement. . I thought this was because I have a space before the >>, but when I remove the space it doesn't work at all. So can someone that understands this convoluted language HELP me figure this out? There is no problem. A TRAILING space for a redirect ( >> ) does not CAUSE a problem. There is no need to remove the trailing space. This complete thread is nonsense. Quote from: marvinengland on June 11, 2010, 01:16:23 PM This complete thread is nonsense. The parts that you contributed are. Why don't you leave? Please. Quote There is no problem. A trailing space for a redirect ( >> ) Don't you REALIZE that there might be something other than human eyes reading this file. @BC_Programmer Thank you. The escape ^ works. I adjusted the code a little. Removed the !in! !in2! !in3! and just made everything !in! because there is no point in using a new variable each time. I also fixed the file name issue. Here is the final code. It works perfectly. No need for any more arguments. Code: [Select]@echo off setlocal enabledelayedexpansion set /p yorn=Would you like to setup the server name etc.(y/n)? if /i %yorn%==y ( set /p in=Maximum clients: echo maxclients !in!> bla.cfg set /p in=Bot limit: echo serverbotlimit !in!>> bla.cfg echo publicserver ^0>>bla.cfg set /p in=Server title: echo serverdesc "!in!">> bla.cfg ) else ( echo said no. ) PS: Does anyone know how to mark resolved on this forum?Quote from: marvinengland on June 11, 2010, 01:16:23 PM A trailing space for a redirect ( >> )@echo off echo Comparing requires no trailing spaces > file.txt set /p var=if not "Comparing requires no trailing spaces"=="%var%" echo FAIL! pause It is also affects FTP scripts, too. Just so you know. |
|
| 2785. |
Solve : i n33d h3lp w/ security batch? |
|
Answer» can someone help me with this? cd C:\DOCUME~1\UBERHA~1\MYDOCU~1 Number of files found Number of files deleted Number of files that could not be deleted Scary?Well, it appears as if it was intended to list batch and vbs scripts which are in various locations and ask the user if each is OK, and if the user says no, delete it. The trouble is that the OP wants a hundred-dollar batch script but only has fifty-cent programming ability. Some advice: Indent your parenthetical STRUCTURES, learn about delayed expansion, learn when to use &. Start SIMPLE and work up to bigger and more complex scripts. could you define:"delayed expansion"??and parenthetical structureQuote from: person1234 on June 22, 2010, 04:09:59 PM could you define:"delayed expansion"?? expansion that occurs in a delayed fashion. Quote from: person1234 on June 22, 2010, 05:40:31 PM and parenthetical structure a structure of a parenthetical nature.Quote from: BC_Programmer on June 22, 2010, 05:44:45 PM expansion that occurs in a delayed fashion.Because we know the OP n33ds h3lp w/ this INFORMATION I can see that you are trying to delete the files. But, this is not a security breach or something. However, let me know where would be the destination folder you are acting on?Quote from: vishuvishal on June 22, 2010, 06:30:12 PM I can see that you are trying to delete the files.what's that mean?? Quote However, let me know where would be the destination folder you are acting on?the startup folder (C:\%USERPROFILE%\STARTM~1\PROGRAMS\STARTUP) |
|
| 2786. |
Solve : Network should return value? |
|
Answer» Hi folks, |
|
| 2787. |
Solve : command line search and copy? |
|
Answer» Hey there. |
|
| 2788. |
Solve : ver in ver? |
|
Answer» how do i GET the echo command in this FILE to work how do i get the echo command in this file to workWhat are you trying to accomplish? echo %a%%b% will echo whatever the contents of %a% and %b% on the screen.Quote echo %a%b%% The syntax of the command is incorrect. Try echo %a%%b% But the environment variables a thru' e haven't been set so how can they be echo'd? desired make the ver b=1 echo %a%b%% ver b expands first making it echo %a1% which is aQuote from: mat123 on June 11, 2010, 08:35:40 PM desired This will make it clear. Batch language does not have arrays, and since variables are expanded at parse time, it is necessary to use call to echo the created variable in a new process, doubling % or ! characters as necessary. Code: [Select]@echo off :a set a1=a set a2=b set a3=c set a4=d set a5=e set /p b=1-5: echo 1 %%a%b%%% call echo 2 %%a%b%%% goto a Code: [Select]1-5:1 1 %a1% 2 a 1-5:2 1 %a2% 2 b 1-5:3 1 %a3% 2 c 1-5:4 1 %a4% 2 d 1-5:5 1 %a5% 2 e 1-5: I figured out a way a couple years back, and used it in a simulation game. Anyway, look at the code, specifically what I highlighted: @echo off Echo Coin flipper pause > nul set t1g4=0 set t1g5=0 set t1g6=0 set t1g7=0 set t2g4=0 set t2g5=0 set t2g6=0 set t2g7=0 cls :begin set /a scriptcount+=1 set /a rnd=%random%%%2 set /a gc+=1 if %rnd% equ 1 (set /a t1+=1) else (set /a t2+=1) if "%t1%"=="4" set t1=0 & set t2=0 & set /a t1g%gc%+=1 & set gc=0 if "%t2%"=="4" set t1=0 & set t2=0 & set /a t2g%gc%+=1 & set gc=0 set /a total1=%t1g4%+%t1g5%+%t1g6%+%t1g7% set /a total2=%t2g4%+%t2g5%+%t2g6%+%t2g7% cls echo Team 1 Wins: %t1% echo Team 2 Wins: %t2% echo ----- echo Amount of games it took to win series: echo ----- echo Team 1 4 Games: %t1g4% echo Team 1 5 Games: %t1g5% echo Team 1 6 Games: %t1g6% echo Team 1 7 Games: %t1g7% echo ----- echo Team 2 4 Games: %t2g4% echo Team 2 5 Games: %t2g5% echo Team 2 6 Games: %t2g6% echo Team 2 7 Games: %t2g7% set /a total=%total1%+%total2% if %total%==1000 goto done goto begin :done pause > nulQuote from: Helpmeh on June 12, 2010, 07:51:26 PM look at the code, specifically what I highlighted: So how do we use that to do what the OP asks? Because I can't get it to work without doubling up the % signs, and using CALL. Use the set command to make a new variable who's NAME contains the other variables.what i REALLY need it for is if statments example set a=1 :a if %b%==5 goto b set /a r%a%=%random% %%5 if %r%a%%==1 set b=a if %r%a%%==2 set b=b if %r%a%%==3 set b=c if %r%a%%==4 set b=d if %r%a%%==5 set b=e set /a a=%a%+1 goto a echo %r1% %r2% %r3% %r4% %r5% Quote from: Helpmeh on June 13, 2010, 06:34:49 AM Use the set command to make a new variable who's name contains the other variables. I see, you are using the fact that set /a does not need percent signs on the variable name on the left hand side of the equals sign. But if you aren't using numbers, you have to use call and the doubled percent signs I posted above. |
|
| 2789. |
Solve : MS Dos Deletes files from the directories on one of the servers? |
|
Answer» NEED HELP! This is the commands i have: ECHO OFF set ConfigFile=config.cfg set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt set wmailto=c:\windows\wmailto.exe set "ExistFreeSpace=0" echo Job starting.... >> %loglocation% date /t >> %loglocation% time /t >> %loglocation% :: ** echo CALLING MDMcreateCSVfiles bat file.... >> %loglocation% :: ** Call MDMcreateCSVfiles :: ** echo Returned from bat file call - continuing.... >> %loglocation% :: ***Check if config file is there if not exist %ConfigFile% ( echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation% %wmailto% -t%loglocation% %email% "-s Config file is missing" goto :eof ) :: *** Call the subroutine; :: *** first argument: the name of the var in the config file to look for :: *** second argument: the batch variable that should have the value assigned. call :ReadConfig TotalDirs TotalNo call :ReadConfig email email call :ReadConfig Warningemail Warningemail call :ReadConfig extension extension call :ReadConfig MinFreeSpacePrcnt MinFreeSpace echo Log space on server.... >> %loglocation% call :FreeSpace ExistFreeSpace >> %loglocation% setlocal EnableDelayedExpansion FOR /L %%i IN (1,1,%TotalNo%) DO ( SET ind=%%i call :ReadConfig Source!ind! source call :ReadConfig OlderThan!ind! olderthan echo Deleting files older than !olderthan! DAYS with the file extension *.%extension% located at !source! >> %loglocation% cd %source% echo . >>%loglocation% ::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% echo Starting delete... >> %loglocation% FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% echo Delete finished... >> %loglocation% echo. >>%loglocation% ) echo. echo All Deletes complete.... >> %loglocation% call :FreeSpace ExistFreeSpace>> %loglocation% date /t >> %loglocation% time /t >> %loglocation% echo >>%loglocation% if %ExistFreeSpace% leq %MinFreeSpace% ( echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation% %wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server" ) %wmailto% -t%loglocation% %email% "-s Files deleted on MDM server" goto :eof :: **** Subroutines start here; no changes below this line ****** :ReadConfig for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a goto :eof :FreeSpace @SETLOCAL ENABLEDELAYEDEXPANSION ::@SETLOCAL ENABLEEXTENSIONS @CLS @FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p @SET /A TotalSpace=!TotalBytes:~0,-9! @SET /A FreeSpace=!FreeBytes:~0,-10! @SET /A TotalUsed=%TotalSpace% - %FreeSpace% @SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! @SET /A PercentFree=100-!PercentUsed! @ECHO TOTAL space: %TotalSpace%GB @ECHO Free space: %FreeSpace%GB @ECHO Used space: %TotalUsed%GB @ECHO Percent Used: %PercentUsed%%% @ECHO Percent Free: %PercentFree%%% ::ENDLOCAL ENDLOCAL &set "%~1=%PercentFree%" goto :eof |
|
| 2790. |
Solve : batch job to show files from network folders from today and yeasterday? |
|
Answer» Hi
C:\test>type yesterdayfiles.bat Code: [Select]@echo off for /f "delims=" %%i in ('cscript //nologo c:\test\evaluate.vbs "date -1"' ) do ( set yesterday=%%i ) for /f "tokens=1,2,3,4 delims=/ " %%a in ("%yesterday%") do set wday=null&set month=%%a&set day=%%b&set year=%%c if %month% LSS 10 set month=0%month% if %day% LSS 10 set day=0%day% set yesterday=%month%/%day%/%year% echo yesterday=%yesterday% set Today=%DATE% set Today=%DATE:~4,10% echo Today=%Today% dir /OD /A-D | findstr "%yesterday% %Today%" rem evaluate.vbs furnished by Salmon Trout rem evaluate.vbs rem Wscript.echo eval(WScript.Arguments(0)) Output: C:\test>yesterdayfiles.bat yesterday=06/08/2010 Today=06/09/2010 06/08/2010 02:46 AM 7 seq.txt 06/08/2010 07:04 PM 8 text1.txt 06/08/2010 07:04 PM 8 text2.txt 06/08/2010 07:04 PM 8 text3.txt 06/08/2010 07:37 PM 379 sw68.bat 06/08/2010 08:10 PM 10 text4.txt 06/08/2010 08:12 PM 339 sw268.bat 06/08/2010 08:59 PM 81 text.txt 06/08/2010 09:34 PM 323 sw4.bat 06/09/2010 08:14 AM 369 sw69.bat 06/09/2010 11:07 AM 184 yesterday.bat 06/09/2010 11:11 AM 3 filecount.txt 06/09/2010 01:11 PM 563 yesterdayfiles.bat C:\test>Hi Thank you very much for replay. I would like to ask you when I run it I have info: ------------------------------------------- yesterday=Input/Error:/Can Today=-06-10 2010-06-10 14:08 603 check files in ready_staying too long.bat ---------------------------- Do you know what can be the reason? I also do not know from where to take: evaluate.vbs - it is in your script. Many thanks for your replay BR RafalAlmost certainly something to do with the date format! Remove the @Echo Off from the top and the commands being processed will be SEEN, not just the error. Note that Marvin's example expects US date formats, you appear to be using military format - you will need to change the order of assignments of day, month and year values to match your locale GrahamQuote from: silberzin on June 02, 2010, 03:25:28 AM
Sib, Gpl is correct. We need the date format for files on your machine. cd to the directory you are working with. C:\>cd c:\test\ c:\test> Do a dir /OD *.xml and | pipe to more. Copy and paste part of that page here. For example: C:\test>dir /OD *.bat | more Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of C:\test 04/24/2010 02:39 PM 1,018 x.bat 04/24/2010 02:39 PM 1,018 buildlog.bat 04/24/2010 06:37 PM 199 matt.bat 04/25/2010 11:27 AM 260 matt5.bat 04/25/2010 11:27 AM 260 matt2.bat 04/25/2010 11:34 AM 307 matt3.bat 04/25/2010 11:41 AM 224 matt4.bat 04/25/2010 02:17 PM 125 ver61.bat 04/25/2010 02:33 PM 190 ver612.bat 04/25/2010 05:14 PM 235 helpme.bat 04/27/2010 12:06 PM 32 chtoE.bat 04/27/2010 07:33 PM 89 fil.bat 04/27/2010 09:52 PM 631 cmpfil.bat 04/27/2010 10:18 PM 698 cmplist.bat 05/05/2010 04:52 PM 192 filefromstr.bat 05/06/2010 12:37 PM 199 hannes.bat 05/06/2010 01:06 PM 194 erasedir.bat 05/07/2010 10:57 AM 229 sw57.bat 05/07/2010 02:16 PM 85 sw58.bat -- More -- also do an echo %DATE% c:\test>echo %DATE% Thu 06/10/2010 c:\test> Create a test directory and copy about 30 of the files you are concerned with. Don't run the code on the large folders until the code is working correctly. ( Forget the vbs code for finding yesterday's date. Enter yesterday's date manually until everything else works. We can find an easier way to find yesterday's date later. ( Or Salmon Trout might show you how to set up the vbs code later. )) Good LuckQuote from: silberzin on June 02, 2010, 03:25:28 AM
The copy and paste from the command window is different than from a web page or word processor. 1) Right click the bar in an open spot at the top just left of the red X. A dropdown MENU will indicate choices: Quote from: silberzin on June 10, 2010, 06:04:32 AM yesterday=Input/Error:/Can C:\test>type dayfiles.bat Code: [Select]@echo off rem dir /OD /A-D > dateformat.txt set Yesterday=2010-06-10 set Today=2010-06-11 echo Yesterday=%Yesterday% echo Today=%Today% findstr "%Yesterday% %Today%" dateformat.txt C:\test>dayfiles.bat Yesterday=2010-06-10 Today=2010-06-11 2010-06-10 12:17 PM 3,173 srcfiles.txt 2010-06-10 03:31 PM 2 bla.cfn 2010-06-11 03:48 AM 17 bla1.txt 2010-06-11 03:48 AM 16 bla2.txt 2010-06-11 01:37 PM 1,624 redirect.bat 2010-06-11 06:09 PM 413 sib611.bat 2010-06-11 06:24 PM 959 yesterdayfiles.bat C:\test>Quote from: silberzin on June 10, 2010, 06:04:32 AM
C:\test>type dayfiles.bat Code: [Select]@echo off rem This program will run automatically at 11:30pm everyday dir /OD /A-D > dateformat.txt dir /OD /A-D > Fdateformat.txt set /p Yesterday=<yesterday.txt for /f "tokens=1,2,3,4 delims=/ " %%a in ("%DATE%") do ( set wday=null&set month=%%b&set day=%%c&set year=%%d set Today=%month%/%day%/%year% set Ftoday=%year%-%month%-%day% ) echo Yesterday=%Yesterday% echo Today=%Today% echo Ftoday=%Ftoday% findstr "%Yesterday% %Today%" dateformat.txt rem echo %Today% > yesterday.txt rem remove "rem" when the program is set to run automatically at 11:30 pm Output: C:\test>dayfiles.bat Yesterday=06/11/2010 Today=06/12/2010 Ftoday=2010-06-12 06/11/2010 03:48 AM 17 bla1.txt 06/11/2010 03:48 AM 16 bla2.txt 06/11/2010 01:37 PM 1,624 redirect.bat 06/11/2010 06:09 PM 413 sib611.bat 06/11/2010 09:10 PM 285 trail.bat 06/11/2010 09:13 PM 39 filehel.txt 06/12/2010 07:23 PM 509 yesterdayfiles.bat 06/12/2010 07:33 PM 14 yesterday.txt 06/12/2010 08:01 PM 7,146 Fdateformat.txt 06/12/2010 08:06 PM 602 dayfiles.bat 06/12/2010 08:07 PM 0 dateformat.txt C:\test>Hi Thank you very much for all your replay. I have a filling that I am close to have solution but unfortunatelly I got lost Is possible for you to publish full code which I should use ?? We would like to schedule this code to be run automatic on one of my colleagues machine, therefore the best is if this program do not require any manual entry and show results on screen + create txt log. Hope that is possible to make Thank you in advance for help BR RafalQuote from: silberzin on June 14, 2010, 12:12:37 AM
I don't know the date format for your files. The following method for finding yesterday's date is not as good as the Salmon Trout method furnished above. But the vbs code was difficult to follow. C:\test>type fday.bat Code: [Select]@echo off echo 2010-06-13 > yesterday.txt rem remove above line after test phase dir /OD /A-D > dateformat.txt set /p Yesterday=<yesterday.txt for /f "tokens=1,2,3,4 delims=/ " %%a in ("%date%") do set wday=%%a&set month=%%b&set day=%%c&set year=%%d echo.Weekday: %wday% echo.Month : %month% echo.Day : %day% echo.Year : %year% set Today=%year%-%month%-%day% echo Yesterday=%Yesterday% echo Today=%Today% findstr "%Yesterday% %Today%" dateformat.txt echo %Today% > yesterday.txt rem only do the above at 11:30 pm Output: C:\test>fday.bat Weekday: Mon Month : 06 Day : 14 Year : 2010 Yesterday=2010-06-13 Today=2010-06-14 2010-06-13 07:23 PM 509 yesterdayfiles.bat 2010-06-13 10:10 PM 722 dayfiles.bat 2010-06-13 10:10 PM 7,146 Fdateformat.txt 2010-06-14 01:05 PM 448 fday.bat 2010-06-14 01:08 PM 10 yesterday.txt 2010-06-14 01:23 PM 0 dateformat.txt C:\test>Quote from: silberzin on June 14, 2010, 12:12:37 AM Is possible for you to publish full code which I should use? C:\test>schtasks /create /SC DAILY /TN test1 /TR c:\test\date.bat /ST 19:35 SUCCESS: The scheduled task "test1" has successfully been created. C:\test>type yesterday.txt The system cannot find the file specified. C:\test>type yesterday.txt 06/14/2010 C:\test>dir /OD yesterday.txt Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of C:\test 06/14/2010 07:35 PM 12 yesterday.txt 1 File(s) 12 bytes 0 Dir(s) 295,454,244,864 bytes free C:\test> Use 23:30 not 19:35 |
|
| 2791. |
Solve : xcopy without replacement? |
|
Answer» I'm trying to write a .bat file (I just started learning msdos and scripting tonight so bear with me) that will backup/copy any new files placed on my jump DRIVE onto my home computer. To do this, right now I'm just running a xcopy command from the command line. However, is there a switch that will tell dos not to copy if the file already EXISTS and hasn't been modified? I was able to copy all the files, but I thought it might be time consuming if everytime I plug it in it has to copy the ENTIRE jump drive, instead of the new files. |
|
| 2792. |
Solve : matrix effect.? |
|
Answer» Hi folks (experts) |
|
| 2793. |
Solve : Run Dialup Networking Using Batch File? |
|
Answer» Hi, I need help, please |
|
| 2794. |
Solve : Save folder with date? |
|
Answer» here's the code... but the question is...
Use a UNIQUE sequence number. A number will work better than a,b,c ... C:\test>type nightrider.bat Code: [Select]@ECHO OFF setlocal enabledelayedexpansion cd C:\test\ type c:\test\backseq.txt SET /p backseq=<backseq.txt echo backseq=%backseq% xcopy c:\test\*.txt C:\backup\recent\*.*> nul for /f "tokens=1-5 delims=/ " %%d in ("%date%") do ( set /a backseq=!backseq! + 1 echo backseq=!backseq! md c:\backup\%%e-%%f-%%g%-!backseq! set newdir=%%e-%%f-%%g%-!backseq! copy c:\backup\recent\ c:\backup\!newdir!\>nul echo Y | rd /s C:\backup\recent\ echo !backseq! > backseq.txt ) cd c:\backup dir Output: C:\test>nightrider.bat 27 backseq=27 backseq=28 C:\backup\recent\, Are you sure (Y/N)? Y Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of c:\backup 06/15/2010 06:29 PM . 06/15/2010 06:29 PM .. 06/15/2010 06:14 PM 06-15-2010-23 06/15/2010 06:17 PM 06-15-2010-24 06/15/2010 06:17 PM 06-15-2010-25 06/15/2010 06:21 PM 06-15-2010-26 06/15/2010 06:22 PM 06-15-2010-27 06/15/2010 06:29 PM 06-15-2010-28 0 File(s) 0 bytes 8 Dir(s) 295,186,542,592 bytes free C:\test>Quote from: night-rider on June 04, 2010, 09:19:05 PM What if back-up the folder at the same date? We may also use time /t instead of sequence number C:\test>type nnrider.bat Code: [Select]@ECHO OFF setlocal enabledelayedexpansion cd C:\test\ time /t > ftime.txt set /p ftime=<ftime.txt set ftime=%ftime::=% echo.%ftime% echo ftime=%ftime% set ftime=%ftime:~0,4% echo ftime=%ftime% xcopy c:\test\*.txt C:\backup\recent\*.*> nul for /f "tokens=1-5 delims=/ " %%d in ("%date%") do ( md c:\backup\%%e-%%f-%%g%-!ftime! set newdir=%%e-%%f-%%g%-!ftime! copy c:\backup\recent\ c:\backup\!newdir!\>nul echo Y | rd /s C:\backup\recent\ ) cd c:\backup dir Output: C:\test>nnrider.bat 0832 AM ftime=0832 AM ftime=0832 C:\backup\recent\, Are you sure (Y/N)? Y Volume in drive C has no label. Volume Serial Number is 0652-E41D Directory of c:\backup 06/16/2010 08:32 AM . 06/16/2010 08:32 AM .. 06/16/2010 07:45 AM 06-16-2010-0745 06/16/2010 07:52 AM 06-16-2010-0752 06/16/2010 07:54 AM 06-16-2010-0754 06/16/2010 08:05 AM 06-16-2010-0805 06/16/2010 08:08 AM 06-16-2010-0808 06/16/2010 08:24 AM 06-16-2010-0824 06/16/2010 08:26 AM 06-16-2010-0826 06/16/2010 08:32 AM 06-16-2010-0832 0 File(s) 0 bytes 10 Dir(s) 294,352,437,248 bytes free C:\test> |
|
| 2795. |
Solve : Batch help: run script only for specific folder? |
|
Answer» Hello all. NEED some help. |
|
| 2796. |
Solve : how to make batch file for all files in faster way? |
|
Answer» i got 10 TEST files to send over lpt1 (copy 1.txt lpt1) |
|
| 2797. |
Solve : Running Shortcut in batch File? |
|
Answer» Hi, I need help, please Path-to-file\winzip.lnk Thanks T.C That's already tested but not working Try this: rundll32 shell32.dll,ShellExec_RunDLL "C:\YOURSHORTCUTHERE.lnk" or if it's a web shortcut, replace .lnk with .url .Quote from: djj99 on June 14, 2010, 07:20:47 PM That's already tested but not working Please explain what happens when you try it, post your script. Quote from: T.C. on June 14, 2010, 07:33:38 PM Please explain what happens when you try it, post your script. Thanks T.C the error same (see below) Quote from: Helpmeh on June 14, 2010, 07:28:22 PM Try this: thanks helpmeh I already tested and still not working The error SAID " windows cannot open this file : YOURSHORTCUTHERE.lnk " Please help me when T.C said: Quote Path-to-file\winzip.lnk you'll notice that you probably don't have a folder called "path-to-file" and that your winzip.lnk is certainly not in it. additionally, when Helpmeh said Quote YOURSHORTCUTHERE.lnk he actually meant for you to put your shortcut's name there. Short story: you can run a lnk/shortcut just as easily as you can a executable. just type the name.Here's ANOTHER example. When running as Administrator I have a shortcut to Winzip.exe on my desktop. To access the file Winzip.lnk in a batch script I would use: "c:\documents and settings\administrator\desktop\Winzip.lnk" where c:\documents and settings\administrator\desktop\ is the path-to-file and winzip.lnk is the filename of the shortcut to Winzip.exe. The " " are necessary as there are spaces in the path, standard requirement of the command shell.Quote from: djj99 on June 14, 2010, 09:24:21 PM The error said " windows cannot open this file : YOURSHORTCUTHERE.lnk " Now I put the shortcut in drive c in root and I put the screen capture the error message [recovering disk space - OLD attachment deleted by admin]Did you create a new file and forced it to have a .lnk extension, or did you properly create a new shortcut?Djj99 - How did you create this shortcut? Did you right click the Winzip.exe file and use SEND To Desktop (Create Shortcut) or Create Shortcut then COPY it to the root of C: or right click on a space on the desktop and create your own shortcut manually or open C: and create a new shortcut there?? No-one has reported any problems in creating or executing shortcuts so what procedure are you using to create them? If you really want help you have to tell us what you are doing... Have you read this or any of these? |
|
| 2798. |
Solve : Result of batch file execution? |
|
Answer» Hi all, |
|
| 2799. |
Solve : remove empty subfolders? |
|
Answer» I have a main folder called : basic and under it are subfolders 1, 2, 3. What I would like to do is remove all the subfolders under "basic" that are empty. Is there are batchfile command that can do this? I've tried: rd c:\basic /s but that removes even "basic".Is this an exercise? Is this needed often? I have a main folder called : basic and under it are subfolders 1, 2, 3. What I would like to do is remove all the subfolders under "basic" that are empty. Is there are batchfile command that can do this? I've tried: rd c:\basic /s but that removes even "basic". rd /s basic is the secret. Then make new basic directory. md basic C:\>rd /? Removes (deletes) a directory. RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path /S Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree. /Q Quiet mode, do not ask if ok to remove a directory tree with /S C:\>rd /S basicthis would be a daily routine task so I prefer not to leave the empty folders there. It is part of a backup routine that backs up folders and files to a central repository and then another application moves it directly to tape. So, every night, a new folder is created. When the tape move OCCURS the files are purged but the folder remains.. I see the second replies suggestion is to remove the entire folder including basic with the RD command and then in the batchfile force the creation of another Basic folder. I thought of that earlier but thought there might be another command that would not require me to recreate the BASIC folder again. ThanksThis may help. Code: [Select]@echo off pushd c:\basic for /r %%r in (.) do ( DIR /b "%%r" | find /v "" > nul && echo %%r NOT empty || rd %%r && echo %%r IS empty...DELETED ) popd You may have to change c:\basic to the correct path.If the subfolders are ALWAYS just 1 LEVEL down from the folder called basic then a simple script like this should do the trick, run from the basic folder Code: [Select]@echo off echo Remove empty folders echo Press a key to start... pause>nul for /f "delims=" %%D in ('dir /b /ad') do ( dir "%%D" | find "0 File(s)">nul && ( rd "%%D" && echo Removed empty directory: %%D ) ) echo Finished echo Press a key to quit... pause>nul it worked. the folders that were not empty stayed and those that were are GONE. Many , many thanks. |
|
| 2800. |
Solve : Limit of number of files for which a Batch script will run onto??? |
|
Answer» Hi all. |
|