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.
| 3401. |
Solve : check to see if variable entered is .txt file? |
|
Answer» NewUser, Like when the date variable has been CHECKED and is valid, I'd like to pass it back into the batch program. Batch will check all dates and anything that needs to be done. Vbs is not needed. See post # 4Strongly suggest ignoring "Joanlong" who is a troll. use a for loop |
|
| 3402. |
Solve : Please teach me more about 2>&1 for stderr Error Redirection? |
|
Answer» When I first saw "2>&1" on this site I thought it was an error, but quickly learnt about this new (to me) facility. |
|
| 3403. |
Solve : MS-DOS RmDir Command? |
|
Answer» Hello: Hello:What is the FULL code in your batch SCRIPT?Dear Helpmeh: Thank you very much for your help. After I received your reply, "What is the FULL code in the batch script", I did some more work on the problem, and I found out what was wrong. The batch file that has the RMDIR command executes from one of the subdirectories that is being removed by the RMDIR command. When I execute my batch program from a different directory, the RMDIR command deletes properly the directory and the sub directories that I want, and then the rest of the MS-DOS commands after the RMDIR command execute as well. Thanks again for all your help. It was very much APPRECIATED. With very best wishes, EdwardQuote from: mellowco on May 27, 2009, 08:43:00 AM Dear Helpmeh:There, if you just leave it for a little while, come back later with fresh thoughts, you're bound to solve it! Feel FREE to stick around to help out other members, or get more help when needed! |
|
| 3404. |
Solve : copy files that created today? |
|
Answer» Hi Gurus, I tried it , but still it is same.no, i have take account for both date format, ddd mm/dd/yyyy or mm/dd/yyyy. double check the code, try to copy & paste all the new code again at post#8. if your time format is 12h, it should display current time on the first line when the batch is executed. additional check (type at cmd prompt): Code: [Select]time/t time/t|find "M" && (echo 12h) || echo 24hand tell me what the resultThanks, IT IS DONE If you miss a day, you'll also miss copying some files because you're limiting your copy to just the files created "Today". If you're using this batch file as a means of backing up critical data files, you might just want to use a BROADER criteria for the files being copied. I use XCOPY to keep all my data files on C: backed up to D: I just incorporated the XCOPY lines into my end of day shutdown script (batch file). When done properly, with the correct SWITCHES, xcopy copies only files that are either new or have been updated since the last backup. My batch file looks something like this: Quote @Echo off On an average day, I may be backing up only one or two files, so the batch file runs and finishes in just a few seconds. It assures that I never shut down my PC with unsaved data files. In this case D: is my backup hard drive. Batch files can get really complicated or you can "KEEP IT SIMPLE". Just add lines to accommodate any folders in your PC that contain valuable data. That would be different for each person. Even though I make a Ghost backup of my entire C: drive, at least once a week, my shutdown batch file assures that I keep all my data files backed up between Ghost backups. So, don't loose your stuff to a HD crash. Backup, Backup, Backup!!! The Shadow thanks for the REMINDER- I myself have been meaning to perform some file management. my 500GB drive is running out of space Thanks for your information on backups. I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS. I need to keep only last 7 days backup files and delete the previous days' file on daily basis. How do I do it in a batch file ? Quote from: kalmazz on May 27, 2009, 07:59:55 AM Thanks for your information on backups.since this question is being ask a lot from day to day, here is an example .hta script. this is my first hta script, so the code is messy & dirty. i couldn't get the progressbar image to work properly and showing file being copied interactively. feel free to modify the code in notepad, it is basically a vbscript wrapped inside html code. WARNING: use at your own risk!!! test first on testing folder [attachment deleted by admin] |
|
| 3405. |
Solve : for loop help? |
|
Answer» I am working on the following for LOOP. |
|
| 3406. |
Solve : How to extract zip file using inbuilt Dos command of Windows XP? |
|
Answer» Hi, Microsoft VBScript runtime error: Object REQUIRED: 'objShell.NameSpace(...)' Here is my code: Code: [Select]strZipFile = "c:\documents and settings\%username%\fr5\resource.zip" outFolder = "c:\documents and settings\%username%\fr5\" Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace(strZipFile).Items() Set objTarget = objShell.NameSpace(outFolder) intOptions = 256 objTarget.CopyHere objSource, intOptions I've checked, retyped the code, copied the code, etc. What am I missing?Quote I used the same script and get the following error: The same script would have worked! In this context, the username variable needs to be expanded: Code: [Select]Set WshShell = CreateObject("Wscript.Shell") user = WshShell.ExpandEnvironmentStrings("%UserName%") strZipFile = "c:\documents and settings\" & user & "\fr5\resource.zip" outFolder = "c:\documents and settings\" & user & "\fr5\" Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace(strZipFile).Items() Set objTarget = objShell.NameSpace(outFolder) intOptions = 256 objTarget.CopyHere objSource, intOptions Everything else being equal, this should work. Thanks, Sidewinder. Worked like a charm. Hey guys. I hope someone is still looking at this thread as I require some help and quite urgently. The unzip seems to be working fine but the files I receive is always named differently because they contain a date and they are password encrepted. How can I specify the password in the script and also tell it to extract all files inside a certain directory not just one? Thanks in advanceQuote Hey guys. I hope someone is still looking at this thread as I require some help and quite urgently This would be reason number one why you should start your own thread. Many people will see this thread with 7 replies and deduce that there is NOTHING more to add. Reason number two is that it is considered rude to hijack someone else's thread, no matter how old. Quote The unzip seems to be working fine but the files I receive is always named differently because they contain a date and they are password encrepted. Use the same algorithm as the sender to determine the received file name. You might also determine what files are in the receive directory, and sequentially unzip each one. Did you use some 3rd party program to compress your files? Windows compressed files don't have a password option and they cannot be encrypted. Need more info. .ZIP folders have the option of having a password to prevent the extraction of the files...also prevents WinRAR from extracting as well.Hi All, I am getting the Error while I am trying to run the Script Test.VBS(5, 1) Microsoft VBScript runtime error: Object required: 'objShell.NameSpace(...)' ndate = date() ndate = ndate-0 strlongdate = formatdatetime(ndate,vblongdate) strshortdate = formatdatetime(ndate,vbshortdate) 'wsh.echo "The yesterday date is : " & cstr(ndate) 'wsh.echo "The long date : " & strlongdate 'wsh.echo "The short date : " & strshortdate strshortdatearray = split(strshortdate,"/") 'wsh.echo cstr(strshortdatearray(0)) 'wsh.echo cstr(strshortdatearray(1)) 'wsh.echo cstr(strshortdatearray(2)) '**********Set these values accordingly to the date format of the machine (2008-01-01)*********** str_short_year = cstr(strshortdatearray(2)) str_short_month = cstr(strshortdatearray(1)) str_short_day = cstr(strshortdatearray(0)) if len(str_short_day ) = 1 then str_short_day = "0" & str_short_day end if if len(str_short_month ) = 1 then str_short_month = "0" & str_short_month end if Option Explicit 'Extract "E:\PrePaid_Data\TN\SFAF\08_BAN_TN_SFAF_" & str_short_year & str_short_day & str_short_month & ".zip", "E:\PrePaid_Data\TN\SFAF\" Extract "E:\PrePaid_Data\TN\01_BAN_TN_ADJM_20090528.txt.zip", "E:\PrePaid_Data\TN" Sub Extract( ByVal myZipFile, ByVal myTargetDir ) Dim intOptions, objShell, objSource, objTarget Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace( myZipFile ).Items( ) Set objTarget = objShell.NameSpace( myTargetDir ) Set colItems = objFolder.Items intOptions = 256 objTarget.CopyHere objSource, intOptions Set objSource = Nothing Set objTarget = Nothing Set objShell = Nothing End Sub ndate = date() ndate = ndate-0 strlongdate = formatdatetime(ndate,vblongdate) strshortdate = formatdatetime(ndate,vbshortdate) 'wsh.echo "The yesterday date is : " & cstr(ndate) 'wsh.echo "The long date : " & strlongdate 'wsh.echo "The short date : " & strshortdate strshortdatearray = split(strshortdate,"/") 'wsh.echo cstr(strshortdatearray(0)) 'wsh.echo cstr(strshortdatearray(1)) 'wsh.echo cstr(strshortdatearray(2)) '**********Set these values accordingly to the date format of the machine (2008-01-01)*********** str_short_year = cstr(strshortdatearray(2)) str_short_month = cstr(strshortdatearray(1)) str_short_day = cstr(strshortdatearray(0)) if len(str_short_day ) = 1 then str_short_day = "0" & str_short_day end if if len(str_short_month ) = 1 then str_short_month = "0" & str_short_month end if Option Explicit 'Extract "E:\PrePaid_Data\TN\SFAF\08_BAN_TN_SFAF_" & str_short_year & str_short_day & str_short_month & ".zip", "E:\PrePaid_Data\TN\SFAF\" Extract "E:\PrePaid_Data\TN\01_BAN_TN_ADJM_20090528.txt.zip", "E:\PrePaid_Data\TN" Sub Extract( ByVal myZipFile, ByVal myTargetDir ) Dim intOptions, objShell, objSource, objTarget Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace( myZipFile ).Items( ) Set objTarget = objShell.NameSpace( myTargetDir ) Set colItems = objFolder.Items intOptions = 256 objTarget.CopyHere objSource, intOptions Set objSource = Nothing Set objTarget = Nothing Set objShell = Nothing End Sub ndate = date() ndate = ndate-0 strlongdate = formatdatetime(ndate,vblongdate) strshortdate = formatdatetime(ndate,vbshortdate) 'wsh.echo "The yesterday date is : " & cstr(ndate) 'wsh.echo "The long date : " & strlongdate 'wsh.echo "The short date : " & strshortdate strshortdatearray = split(strshortdate,"/") 'wsh.echo cstr(strshortdatearray(0)) 'wsh.echo cstr(strshortdatearray(1)) 'wsh.echo cstr(strshortdatearray(2)) '**********Set these values accordingly to the date format of the machine (2008-01-01)*********** str_short_year = cstr(strshortdatearray(2)) str_short_month = cstr(strshortdatearray(1)) str_short_day = cstr(strshortdatearray(0)) if len(str_short_day ) = 1 then str_short_day = "0" & str_short_day end if if len(str_short_month ) = 1 then str_short_month = "0" & str_short_month end if Option Explicit 'Extract "E:\PrePaid_Data\TN\SFAF\08_BAN_TN_SFAF_" & str_short_year & str_short_day & str_short_month & ".zip", "E:\PrePaid_Data\TN\SFAF\" Extract "E:\PrePaid_Data\TN\01_BAN_TN_ADJM_20090528.txt.zip", "E:\PrePaid_Data\TN" Sub Extract( ByVal myZipFile, ByVal myTargetDir ) Dim intOptions, objShell, objSource, objTarget Set objShell = CreateObject( "Shell.Application" ) Set objSource = objShell.NameSpace( myZipFile ).Items( ) Set objTarget = objShell.NameSpace( myTargetDir ) Set colItems = objFolder.Items intOptions = 256 objTarget.CopyHere objSource, intOptions Set objSource = Nothing Set objTarget = Nothing Set objShell = Nothing End Sub Resolve Any ONE ASAP............................ |
|
| 3407. |
Solve : 2 part question about date in a batch file? |
|
Answer» Part 1: Part 2: I doubt if this is achievable using only batch scripting, VBS might be better for this part, perhaps one of the VBS gurus will drop in. Meantime here's another version of batching to create the filename in the format you requested using the 24-hour clock (aka Military Time). The underlined command lines should be removed when you are finished testing. Your date format is assumed to be 'day mm/dd/yyyy' and the time format as 'hh:mm:ss.ms AM (or PM)', When the hour is less than 10 it's assumed it is shown as one digit. Code: [Select]Script removed. Edit: See amended script below....As a suggestion you could try extracting it with the Set command Code: [Select]@echo off set nummonth=%Date:~4,2% set day=%Date:~7,2% set year=%Date:~12,2% set hour=%Time:~2% set min=%Time:~3,2% if %hour% LSS 10 set hour=0%hour% for /f "tokens=%nummonth%" %%a in ('echo JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC') do ( set wordmonth=%%a ) Then for the ZIP paramater you can just put: Code: [Select]%day%%wordmonth%%year%_%hour%%min%.ZIP For part two, you would have to use a 3rd party program or perhaps Cscript. I'll get back with the Cscript instructions. Hope this helps ,Nick(macdad-)Thanks T.C. and macdad. T.C.'s method worked well. Macdad, your method left some extra spaces and inserted a : into the file name, so that was invalid. Thanks to everyone for answering.Quote from: JohnBergt on November 25, 2009, 05:08:29 PM T.C.'s method worked well. You SPOKE to soon John, there is a glaring error in my script. In the command line Code: [Select]for /f "tokens=%date:~4,2%" %%1 in ("%alphamonth%") do ( set month=%%1 ) if the month is 08 or 09 (Aug or Sept) tokens will FAIL probably due to 08 and 09 being invalid octal numbers. Amended script posted below, sorry about the error. Code: [Select]@echo off cls setlocal enabledelayedexpansion set date=fri 09.26.2009 :: -------------------- set alphamonth=JAN FEB MAR APL MAY JUN JUL AUG SEP OCT NOV DEC if %date:~4,2% lss 10 (set monthnbr=%date:~5,1% ) else ( set monthnbr=%date:~4,2% ) for /f "tokens=%monthnbr%" %%1 in ("%alphamonth%") do ( set month=%%1 ) set today=%date:~7,2%%month%%date:~-2% set time=1:12:13.14 am :: ------------------- for /f "tokens=1-4 delims=: " %%1 in ("%time%") do ( set hour=%%1 set min=%%2 if /i %%4 equ pm if %%1 lss 12 set /a Hour +=12 ) if %hour% lss 10 set hour=0%hour% set time=%hour%%min% echo.&echo. echo Today=%today% Time=%time% echo.&echo. echo Filename=%today%_%time%.zip Script edited to allow for correct display of times between 12.00 (noon) and 1.00 pm date manipulation has been discussed countless times. Don't use batch for date manipulations. try learning and using vbscript if you are a native guy, or get a real programming language, Perl/Python are the ones you need.Quote from: gh0std0g74 on November 26, 2009, 02:53:27 AM date manipulation has been discussed countless times. Don't use batch for date manipulations. try learning and using vbscript if you are a native guy, or get a real programming language, Perl/Python are the ones you need. I believe this vbscript should do the job.Quote from: gh0std0g74 on November 26, 2009, 02:53:27 AM Don't use batch for date manipulations. try learning and using vbscript Sorry, I cannot agree with that. While it is a good idea to learn VBScript etc., when a member asks for a solution to a problem using batch scripting he/she should be assisted to achieve that solution in the scripting language of his/her choice not told to go off and learn another language with which he/she may have no experience. Certainly batch scripting is very limited in some areas, and date manipulation is one of them, but if the request is for assistance in a batch script that assistance should be forthcoming where it is possible. Then, and only then, should the suggestion be made to expand into VBS etc...Quote from: T.C. on November 26, 2009, 12:04:51 PM Batch Works. Code: [Select]@echo off setlocal enabledelayedexpansion date /t > sdate.txt set /p sdate=<sdate.txt echo sdate=!sdate! set alphamonth=JAN FEB MAR APL MAY JUN JUL AUG SEP OCT NOV DEC set tokens=%sdate:~4,2% echo tokens=!tokens! for /f "tokens=%date:~4,2%" %%a in ("%alphamonth%") do ( set month=%%a echo month=!month! ) set today=%date:~7,2%%month%%date:~-2% time /t > stime.txt set /p stime=<stime.txt echo stime=!stime! for /f "tokens=1-4 delims=: " %%a in ("%stime%") do ( set hour=%%a set min=%%b set pmm=%%c echo hour=!hour! echo min=!min! echo PM=!pmm! if !pmm! equ PM set /a hour=!hour! + 12 echo hour = !hour! ) if %hour% lss 10 set hour=0%hour% set time=%hour%%min% echo.&echo. echo Today=%today% Time=%time% echo.&echo. echo Filename=%today%_%time%.zip Output: C:\>fdate.bat sdate=Wed 11/25/2009 tokens=11 month=NOV stime=11:40 PM hour=11 min=40 PM=PM hour = 23 Today=25NOV09 Time=2340 Filename=25NOV09_2340.zip Output for 11/26/2009: C:\test>joan.bat sdate=Thu 11/26/2009 tokens=11 month=NOV stime=04:15 PM hour=04 min=15 PM=PM hour = 16 Today=26NOV09 Time=1615 Filename=26NOV09_1615.zip C:\test> Quote from: T.C. on November 26, 2009, 12:04:51 PM Sorry, I cannot agree with that.you do not agree because i said "Don't use batch for date manipulation"? or you don't agree that i asked OP to learn and use something else that is better at doing this job? Quote While it is a good idea to learn VBScript etc., when a member asks for a solution to a problem using batch scripting he/she should be assisted to achieve that solution in the scripting language of his/her choice not told to go off and learn another language with which he/she may have no experience.you must understand that this is a forum, and we are allowed to suggest BETTER and EASIER alternatives to SOLVE the problem. What really matters is OP's choice of solution, not yours or mine. No experience in learning something he did not know?? If OP has experience in batch, he wouldn't have asked here already. so what's your point? Quote Certainly batch scripting is very limited in some areas, and date manipulation is one of them, but if the request is for assistance in a batch script that assistance should be forthcoming where it is possible. Then, and only then, should the suggestion be made to expand into VBS etc...as far as i already know, you have provided a batch (that may not work in every machine due to individual date settings). I/macdad have provided suggestion using vbscript and all that's left is up to OP. A challenge for you, try producing a batch to convert local to UTC for OP then, if you really meant what you say.Quote from: GD A challenge for you, try producing a batch to convert local to UTC for OP then, if you really meant what you say. GD - You obviously did not read my first response to JohnBergt, did I not state Quote Quote from: JohnBergtPart 2: One of the VBS gurus did drop in but unfortunately didn't leave a solution. Quote from: GD as far as i already know, you have provided a batch (that may not work in every machine due to individual date settings). Quite correct, it will not work for date settings other than the ones I stipulated in my first response: Quote Your date format is assumed to be 'day mm/dd/yyyy' and the time format as 'hh:mm:ss.ms AM (or PM)', When the hour is less than 10 it's assumed it is shown as one digit. How can I make that clearer? I have no wish to become involved in a drawn out argument about the merits of Batch Scripting vs VBS, I also believe VBS is superior in many ways than Batch but still believe that if a solution to a problem is asked for in batch scripting and that solution can be arrived at then it should be given. Kind regards to all. T.C. Quote from: T.C. on November 26, 2009, 08:24:33 PM GD - You obviously did not read my first response to JohnBergt, did I not statedon't worry, i did read your post before posting my last response. Quote but still believe that if a solution to a problem is asked for in batch scripting and that solution can be arrived at then it should be given.so is there a clean and understandable batch(cmd.exe) solution given yet to take into account, different regional date settings on different machines, and the ability to convert to UTC time easily?? Your reasoning that batch solution should be given is flawed. most of the time, the ones posting questions here either did not know there are better alternatives, or they just have the mentality that says batch does everything. What's wrong with posting better alternatives that do the job in half the time it takes to do it in batch? you are beginning to sound that the other "hated" person around here. I suggest you focus more on providing solution to the OP and stop meddling with trivial things like this. Quote from: JohnBergt on November 25, 2009, 09:04:59 AM
http://www.timeanddate.com/worldclock/converted.html?month=11&day=29&year=2009&hour=0&min=0&sec=0&p1=0&p2=184 The World Clock – Time Zone Converter – results At the specified time, local time in Oklahoma City was 6 hours behind UTC LocationLocal timeTime zone UTCSunday, November 29, 2009 at 00:00:00 Oklahoma City (U.S.A. - Oklahoma)Saturday, November 28, 2009 at 6:00:00 PMUTC-6 hours CST It appears Batch is the best solution for the first part of your question. See Post # 9 UTC is a minor problemthen , Miss genius, can you show a complete batch solution to do both part 1 and 2? |
|
| 3408. |
Solve : How to compile a .bat file? or write a simple .exe to call it?? |
|
Answer» Hi, |
|
| 3409. |
Solve : Hello - I would like some help.? |
|
Answer» It's with MS-Dos, duhh |
|
| 3410. |
Solve : save files and transfer to usb key?? |
|
Answer» Basically before i wipe the hardrive and INSTALL win 7 again i was wondering if this is possible in mdos? |
|
| 3411. |
Solve : A batch file do a automatic copying and renaming job with conditions like this?? |
|
Answer» Hello, I'm NEWBIE in command prompt console and want to ask something about my issue. I try some way to write a batch file do this job but unsucessfully. Pls someone help me out and pls write code in details (for my question, don't just tell me generally and tell me find out myself With an attitude like that, you'll never learn anything. Would have been better to post your unsuccessful attempt. It would have shown that you at least made an attempt for a solution. C:\batch>type winder122109.bat Code: [Select]@echo off set source=E:\MPEGAV set target=C:\Documents and Settings\%username%\My Documents cd %target% dir *.dat rem del *.dat ( remove "rem" if you need to remove .dat files ) for /f %%x in ('dir /b %source%\*.dat') do ( for /f "tokens=1-4 delims=:." %%i in ("%time%") do ( if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat" ) else ( copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat") ) ) cd %target% dir *.dat Output: C:\batch>winder122109.bat Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of %target% 12/21/2009 11:18 AM 9 me.dat-17320759.dat 12/21/2009 11:18 AM 9 me2.dat-17320759.dat 2 File(s) 18 bytes 0 Dir(s) 305,583,677,440 bytes free 1 file(s) copied. 1 file(s) copied. Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of %target% 12/21/2009 11:18 AM 9 me.dat-17333304.dat 12/21/2009 11:18 AM 9 me2.dat-17333304.dat 2 File(s) 18 bytes 0 Dir(s) 305,583,677,440 bytes free @BillRichardson: I thought you were banned. In any case if you noticed an error, why did you not simply fix it? Apparently anybody can be a critic, but if you're going to re-post code at least be accurate. I posted: if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l" ) else ( copy %source%\%%x "%target%\%%x") which I admit was in error. You posted: if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat" ) else ( copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat") which is also in error. The corrected code: Code: [Select]@echo off set source=F:\MPEGAV set target=C:\Documents and Settings\%username%\My Documents for /f %%x in ('dir /b %source%\*.dat') do ( for /f "tokens=1-4 delims=:." %%i in ("%time%") do ( if exist "%target%\%%x" (copy %source%\%%x "%target%\%%nx-%%i%%j%%k%%l.%%xx" ) else ( copy %source%\%%x "%target%\%%x") ) ) I always thought we were here to help out the OPs. Keep in mind BillRichardson these threads are not about you but about the Topic Starters. That's all I have to say...I refuse to get involved in a marathon thread with BillRichardson, et al. Quote from: Sidewinder on December 21, 2009, 05:23:21 PM @BillRichardson: _____________________________________ I respect your code and judgement more than anyone on this board. You code is much better than mine. I learn by running your code. The output always helps me. I thought the new file names should have a ".dat" at the end? I might have run the code incorrectly or had my folders set up wrong? I will erase or change the code as you suggest. Tell me exactly what to change. Is it wrong to show the output? I will do whatever you suggest. Thanks for your help several times in the past. Quote With an attitude like that, you'll never learn anything. Would have been better to post your unsuccessful attempt. It would have shown that you at least made an attempt for a solution. Well, I don't know if you're helpful for anyone previously, but not me... You just come and sounds like /I'm god, u're lazy boy, keep learning!/ Because there's people like you I wrote my question with those sentences above. I don't have to be a expert in command prompt console and I don't need to be someone like that. I'm here for get some help no matter how good/bad am I (in computer experience), people'd give a hand or not, it's their choice. You don't need to stay there and say that, it's too pointless thing after all~ 4rum just make for give people a chance to get help and it doesn't REQUIRE that much conditions (in rules, I don't see that I've to post all my attempt and etc....) Feel free ban nick or lock acc if u want. Don't worry, everybody is entitled to their opinion and you will not be banned for expressing yours. It's been said here and elsewhere "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime." Apparently you just want someone to hand you a fish. I must have been very tired last night, but post #6 (the corrected code) has an error. The corrected code (v2) is posted below. Take it for what it's worth. Code: [Select]@echo off set source=F:\MPEGAV set target=C:\Documents and Settings\%username%\My Documents for /f %%x in ('dir /b %source%\*.txt') do ( for /f "tokens=1-4 delims=:." %%i in ("%time%") do ( if exist "%target%\%%x" (copy %source%\%%x "%target%\%%~nx-%%i%%j%%k%%l%%~xx" ) else ( copy %source%\%%x "%target%\%%x") ) ) Quote I'm here for get some help no matter how good/bad am I (in computer experience), people'd give a hand or not, it's their choice I'll keep that in mind the next time you post. It will save me the aggravation of reading another one of your rants. Quote I'll keep that in mind the next time you post.OK, keep TALKING yourself about that. Don't start with fish and blah blah things... I'm working as a graphic artist and I can live without cmd, alright? I'm not a kid for you talk to me like that. And I don't need any ggdamn fish, just need a accurate and correct answer for my question, if it hurt your ego, then it's not my mistake. Thanks for nonetheless. You live as a IT supporter or programmer or whatever, me too. Then don't personally attach me about fish and etc...Quote from: nah on December 22, 2009, 07:48:15 AM OK, keep talking yourself about that.Nah, that wasn't an attack. He is just explaining that people who get taught how to do this understand it for a lifetime, no longer need help, and can even help others out (that's what happened to me), but people who only want the answer, they need help for the rest of their life. Quote from: nah on December 20, 2009, 06:56:40 AM I want make a batch file do this task. You were given at least 3 possible solutions. Which solution worked for you? |
|
| 3412. |
Solve : Merging the contents of two files, into one file? |
|
Answer» Hi there, Let's suppose that both files are valid spreadsheet files.The files are not valid spreadsheet files. A csv-file is a text file that excel can read by conversing a dot comma as the END (or start) of a new column in excel (B-column) Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM Does that make sense to you? The dos commands as shown above, already works. Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM If your intent is to just combine the two files together for the purpose of documentation that would be an acceptable thing. Otherwise, if you really want that to spreadsheets to work together as one, you would have to use the features inside of XL two combined to spreadsheets together. It makes a csv files, which excel can convert. the Master.csv works well in excel Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM Possibly, you would have to create a book inside of XL and each spreadsheet would be a separate page inside of one book. Then you would have to do some additional work so that the output of one page could be referenced on the second page and perhaps a sum total of the entire project could be given on the third page. The data is shown in one page, inside the file Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM By the way, is this some type of homework assignment? A serious work related problem, which needs a quick fix! Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM Was this of any help? Or did I just make things worse? You decide |
|
| 3413. |
Solve : New mbr - seeking direction and capabilities of batch files? |
|
Answer» Hey ya’ll. |
|
| 3414. |
Solve : I need help with this code of inject.exe? |
|
Answer» ur right BC_Programmer yes salmon "I BET" And you never will while you keep posting nonsense. Quote from: great_compressor_pain on November 30, 2009, 05:52:14 AM it packs any means any files in 1 single file Hey WinZip and WinRAR do the same thing. Do you want the code for them too? *censored* is your bloody question? WHAT do you want? "the codes" as I've just stated is so meaningless, redundant, ambiguous and all-around script-kiddie to say that it doesn't specify at all what you want. s ofar as I've just stated there are several possiblilities: 1. Either you want the actual source code to this program, which none of us can provide since we didn't write it. 2. you want somebody to write a program that does the same thing, and give you the source to that 3. you simply want to know what command-line options the program has. So which is it? stop SAYING "it packs files" and "it's by some dude" Start giving us some frikkin' details rather then making contrived observations about the PROGRAMS BEHAVIOUR that you erroneously believe somehow GIVES us some idea what you want. Oh! And by the way, inject.exe is infected. thought you might like to know- since you probably RAN it and all. Quote from: great_compressor_pain on November 30, 2009, 06:01:39 AM and as i said i've got the right guy No. You don't. I still have no clue what the heck you want. Profanity reported. heh, I was wondering how long it would take for him to get help with his keygens/file injectors and other sketchy stuff elsewhere.Pain is heading to drink a tall cool glass of Ban Cola. Quote from: Salmon Trout on November 30, 2009, 06:07:55 AM Pain is heading to drink a tall cool glass of Ban Cola. Or he deleted his account - he's a "Guest" now. Another one bites the dust |
|
| 3415. |
Solve : How to run a batch file inside a zip archive from a batch file?? |
|
Answer» Here is the path of the working folder. |
|
| 3416. |
Solve : Error message when files not found? |
|
Answer» Gudday all File not foundand the temporary file SPLfiles.txt is not deleted as it should be. Why is the message 'File not found' being generated? I do not want the code to fail if no .spl files are found. Or more particularly can I stop it? And why would the file not be deleted if indeed the non-deletion is due to the error message?Code: [Select]echo finding spl files rem *** Extract all .SPL files *** rem dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt if exist "!file_path!*.spl" ( dir !file_path!*.spl /b > SPLfiles.txt echo finished finding spl files ) else ( echo No .spl files found ) ..... del SPLfiles*.txtST Thank you. So much to learn. |
|
| 3417. |
Solve : Wacky Question with Batch files.? |
|
Answer» I used and edited batch files back in the day, but i can't remember if they can be used to wait on a program. |
|
| 3418. |
Solve : Scripting Help2? |
|
Answer» Im trying to create a game in batch. I am beginning to get worried since many of my scripts seem to not be working. Can cmd break? @echo offbatch is not really used for creating games or programming in general. When adding or subtracting integers in batch, use SET /A. Example: set /a varname+=1 set /a var2=%varname%^2/40 You can use brackets, as you normally would. Note: +=addition -=subtraction *=multiplication /=division ^=exponent ?=roots. I don't KNOW this one. Quote from: Helpmeh on December 23, 2009, 06:47:12 AM
Don't know where you got that from. According to the SET help, viewed by typing SET /? at the prompt they are Code: [Select] () - grouping ! ~ - - unary operators * / % - arithmetic operators + - - arithmetic operators << >> - logical shift & - bitwise and ^ - bitwise exclusive or | - bitwise or = *= /= %= += -= - assignment &= ^= |= <<= >>= , - expression separator Quote from: Salmon Trout on December 23, 2009, 07:47:59 AM Don't know where you got that from. According to the SET help, viewed by typing SET /? at the prompt they areI put the question mark because I didn't know. |
|
| 3419. |
Solve : Delete system restore points?? |
|
Answer» Hi there, They take a lot of spaceWhat is a lot of space? Using that kind of thought, let's all remove the spare tire and jack from our automobiles. We hardly ever NEED them.When I installed Windows XP in October 2001, I disabled System Restore. Since then, I have never missed it. I prefer to run my own backup strategy. Every Saturday morning, and also before updating "mission critical" software or altering something major, I make a backup of my system partition. I keep about the last 4 or 5 backups. I formerly used Norton (Symantec) Ghost, but now I uses Paragon 9.5. I must say, for an average user, disabling system restore is not a good idea.For the average user, it is probably isn't a good idea. Then again if you backup your data (like you supposed to), and are safe in your browsing habits then I don't see any real problems with cleaning that out. Because the problem is that it keeps way too much back history. If your MACHINE is functioning perfectly, a good clean up keeps it running. Even removing System Restore points is a good way to do that. Most people would never go back three months for a system restore because that would end up breaking things they have legitimately installed (like Windows Updates, etc.) I wouldn't disable it permanently unless you're willing to deal with the PC when things go faulty without having a restore point to try. So, in my opinion, disable it then enable it and create a good restore point to clean up the machine is fine for a functional PC. if you want to reduce the space it consumes... change the option accordingly. System Restore has a user-set limitation for each drive. Having fewer restore points doesn't speed up the PC. It frees up disk space, but if your desperate enough for extra space to start clearing restore points, maybe it would be better to more fully analyze disk usage in other locations, or buy a bigger hard drive. Quote or buy a bigger hard drive. Yes, I wanted to say that. Hard disk drive prices are now lower than ever. If top performance of the drive is not an issue, you can GET a refurbished IDE drive guaranteed by the factory at a bargain price. This is a great choice for backing up your videos, your photos, your downloads and any other stuff that takes up space that you do not use it every day. This link is from a major vendor. You can get a 250GB drive with a warranty for well undrer $100. That would hold as much data as 50 DVDs. http://www.compusa.com/applications/category/category_tlc.asp?CatId=134&SRCCODE=COMPGOOHDD&cm_mmc_o=7BBTkwCjCmH4CjCmH4CjCmH4The System Restore feature has its good and its bad points. Good: it allows you to easily protect the integrity of the Windows OS without having to take the time to create a full-fledged backup. Bad: it does not protect user files such as documents, Internet Explorer favorites, the contents of your recycle bin, graphics files, etc. It doesn't protect against a hard disk failure. and nor does it protect from re-infection of malware. It can hide there waiting for you to need a system restore. You thought you were clean, but do a system restore and the mess gets reinstalled just like before. That is why after I clean a machine of malware, I always delete the restore points and create a new one (clean). But also, if you have an exact date of malware infection, a system restore previous to that date can put you back into working order (not really clean, but working). That is why I still use it, but I just like to keep it cleaned out from time to time. |
|
| 3420. |
Solve : backup certain files? |
|
Answer» Hi there |
|
| 3421. |
Solve : retrieve data from an application? |
|
Answer» I have no programming knowledge but was given a group of files created in 1997 that together make up a FULLY functioning very basic custom invoicing program. With this program you can view invoices and create NEW ones. It is only controlled by keyboard functions. These are the files COMPRISING this program: |
|
| 3422. |
Solve : Deleting files in External Drive? |
|
Answer» I had been using an external drive to back up music and such. However, due to user ineptitude I allowed it to make multiple copies of each file, some of which have a .dcm file extension attached to them. Dealing only with my music folders, I would like to REMOVE all files except those which end in .wma and .jpg. I have a notion of where to start: I am (much) less sure of that, but right now, I can't seem to get out of the gate: when i try to switch directories, nothing happens. For example:Just type e: ( leave the cd out) Quote I had been using an external drive to back up music and such. However, due to user ineptitude I allowed it to make multiple copies of each file, some of which have a .dcm file extension attached to them. Dealing only with my music folders, I would like to remove all files except those which end in .wma and .jpg. I have a notion of where to start:I'm assuming you want to delete all file ending in .dcm with names such as e:\backup files\music\album1\allsongs.dcm,e:\backup files\music\album2\allsongs.dcm, etc.... Code: [Select]DEL "e:\backup files\music\*.dcm" /sWill remove all files under the music dir with the extension .dcm Quote After that I want to remove multiple copies of the same files, which appear as following:What kind of random date format do you have? If all of the files you want to delete end in 09.wma for example and you have no files you want to save ending in 09.wma you COULD use Code: [Select]del "e:\backup files\music\*09.wma" /s That will delete all files ending in 09.wma in all sub directories of music to change drives type the drive letter and a colon e.g. D: and then [ENTER] to change to a folder on a different drive use the cd command with the /d switch Say you are in "C:\My Folder\EggPlant" and you want to be in "E:\Music Files\Led Zeppelin" you could type either: E: [ENTER] cd "Music Files\Led Zeppelin" [ENTER] or just one line cd /d "E:\Music Files\Led Zeppelin" [ENTER] And you will now be in the folder on the other drive. If you now type C: and press ENTER, you will go back to the C: drive, to the same folder on that drive that you were in before. Thank you Salmon Trout and Crusin702 for the assistance, especially with such rookie questions. @Crusin702: The random dates do not consistently end in any digit. For example: .08 [emailprotected];42;59.wma However, all of the files consistently have an @ symbol included in them. I don't believe any of the song titles include that symbol, so is it possible to delete all files that include "@"? The code you provided for deleting files that .dcm does not seem to be working. It keeps telling me that it can't find the files (see the attachment) Thanks again! [Saving space, attachment deleted by admin]Quote from: kovan on December 25, 2009, 12:57:53 PM is it possible to delete all files that include "@"? del *@*Thanks Salmon Trout, that worked perfectly. I tried using that same trick to delete the .dcm files, but it still tells me that it can't find the files.In fact, none of the files ending in .dcm that contain an @ symbol were deleted either. Is it possible the software provided my memeo prevents these files from being located? Sounds as if what you actually saved is shortcuts to where the files used to be...I just did a quick search and it seems the .dcm files are created by the hd software for backup and restoration purposes. Have you tried to delete any of them using explorer? If you can delete them that way, maybe just run a search for .dcm and select all and delete them that way. |
|
| 3423. |
Solve : Please test this batch script.? |
|
Answer» The script uses Extended ASCII codes and I want to determine if the default codes differ across Windows systems especially Vista and Win 7 variants. (a) Copy the script to your clipboard. command.com -> edit.com -> pasted -> saved as bat script (1) run in command.com (command window font set to 7x12 raster font) (2) same batch run in cmd.exe (7 x 12 raster font) Quote from: Dusty on December 25, 2009, 01:21:03 PM I have found that the Extended Ascii codes are changed when the script is pasted into Edit.com running in Cmd.exe so the output there is not what is wanted, but, when the script is pasted into Edit.com running in Command.com the codes are properly pasted and the output is aok. cmd supports- or tries to support, unicode. command.com does not. Either way, you cannot run edit.com from within cmd; it spawns command.com to run it anyway, not sure exactly where the issue lies, but I assure you it has to do with unicode/ANSI support. If you save as ANSI encoded in any text editor your batch will work (given that the fonts match)Salmon Trout - Thank you again, that's exactly what I was trying to replicate. BC-P - sorry, I'm not sure what you mean. Quote If you save as ANSI encoded in any text editor your batch will work (given that the fonts match) It's been shown that attempting to save the script using Notepad brings up the warning shown below even when Ansi encoding is selected. Selecting Unicode MAKES the script unusable. Quote from: Salmon Trout on December 25, 2009, 03:29:24 AM Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.Quote from: BC_Programmer on December 25, 2009, 06:36:30 PM Quote from: Salmon TroutFinally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above. Yeah, sure, the script runs but does not produce the REQUIRED output because the Extended Ascii chars have changed as shown in Salmon Trout's screen capture in reply #3. After saving the copy/post into Edit.com running in Command.com the script runs correctly and produces the required output as shown in Salmon Trout's reply #5. Thank you for your interest, would you run the script in Vista and post your results please? Quote from: Dusty on December 25, 2009, 10:01:12 PM Yeah, sure, the script runs but does not produce the required output because the Extended Ascii chars have changed as shown in Salmon Trout's screen capture in reply #3. none of the character codes were changed. Quote I am using Consolas as my console window font. (Not every console font has the same characters above ASCII 127.) and then, in the later screenshots: Quote (command window font set to 7x12 raster font) this is the key. Anyway, I ran it on mine, and even though I was using Raster fonts, I still got the same characters as Salmon Trout: I decided to investigate. the issue is rooted solely in code pages. When I visited character map and went to the code that corresponded to the character I saw, it was there, within the same set of fonts. under the same code. This was odd. BUT! I changed the "character" in character maps "advanced" section to "DOS-US" and the line drawing characters were there. Since I'm on Vista x64 I cannot run edit and it isn't included with my OS. I was able to get agreeable results by "cheating" what I did, was I copied the batch file to the clipboard, used the command "copy con D:\test.bat" and used the cmd "paste" feature, followed by Control-Z and enter. I did end up with an extra @echo off line at the top, but it has no impact on the functionality. I ran the batch resulting from this, and success!: So it works, as long as the batch os created properly, in vista x64. As it is now, there are a LOT of encoding conversions to get it on other machines, copy from browser, paste to editor, etc. So, I decided to simply plop it in a text file and attach it as is. this way, the file should be relatively untainted by any data manipulation performed by the OS during copy paste, and it will be easier for others using other operating systems to test... in fact... test on my win 7 laptop: Note: these are both x64 systems; I'd imagine it will work fine on x86 versions of these Operating Systems, too. [Saving SPACE, attachment deleted by admin]BC_P - thank you, the results you produced are greatly appreciated. D.. |
|
| 3424. |
Solve : Wanted a command line Software? |
|
Answer» Hi Guys yep ive tried every thingreally? have you tried to search for mencoder (or ffmpeg?") |
|
| 3425. |
Solve : How to zip file one by one thru command line? |
|
Answer» Hi Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment. I believe my sed version is for 32-bit and the creation date is 2005. The simple substitution(s) of one pattern in a file name for different pattern seems to work ok. sed s/011209/021209/ datfile.txt p.s. I have not used 64-bit Quote from: Geek-9pm on December 28, 2009, 08:31:24 PM Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment. better to use GNU ones....see my sigQuote from: ghostdog74 on December 28, 2009, 09:50:24 PM better to use GNU ones....see my sigThanks, my beady LITTLE eyes did not see that before. Here is the link in big letters. http://gnuwin32.sourceforge.net/packages.html |
|
| 3426. |
Solve : CDROM in Batch File? |
|
Answer» Hello, |
|
| 3427. |
Solve : if and set? |
|
Answer» where can i find the FILES for the if and set command on my COMPUTER i NEED them for compatibility of my batch file.If and Set are internal commands and are available only in the CMD shell. i need them for compatibility of my batch file.What??? EXTERNAL commands and CMD internal commands are SHOWN here http://ss64.com/nt/ |
|
| 3428. |
Solve : Delete redundant files from backup folder? |
|
Answer» Hi there, I've had a search through the forum and couldn't find anything specific to my query but if there is already a post related to it I'd be happy to be pointed in the right direction. Robocopy.exe: ROBUST File Copy UtilityWindows Server 2003 Resource Kit ToolsQuote from: Geek-9pm on April 28, 2010, 11:12:25 AM Windows Server 2003 Resource Kit Tools it also comes with Vista and Windows 7 by default. |
|
| 3429. |
Solve : ERRORLEVEL = 0 within FOR loop? |
|
Answer» I have posted previously about my DR check batch file, but just one issue remains... \autoexec.bat The for loop contains; - I changed the FIND to wwwwwwww to force a failure. Code: [Select]set TIB=example.txt set SERVER=C: for /f "eol=; tokens=* delims=" %%i in (%TIB%) do ( dir "%SERVER%%%i" | find "wwwwwwww" >nul if %ERRORLEVEL%==0 ( echo Located - %SERVER%%%i >> %logfile% ) ELSE ( echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile% ) ) For some reason ERRORLEVEL always RETURNS zero even if the file doesn't exist, I'm assuming that's because the FOR command didn't error even though the dir command did. If I run the DIR command outside the FOR loop it returns errorlevel 1 Does ANYBODY know of a way around this?you can try Code: [Select]set TIB=example.txt set SERVER=C: for /f "eol=; tokens=* delims=" %%i in (%TIB%) do ( dir "%SERVER%%%i" | find "wwwwwwww" >nul if ERRORLEVEL 1 ( echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile% ) else ( echo Located - %SERVER%%%i >> %logfile% ) ) Or: setlocal enabledelayedexpansion set TIB=example.txt set SERVER=C: for /f "eol=; tokens=* delims=" %%i in (%TIB%) do ( dir "%SERVER%%%i" | find "wwwwwwww" >nul if %ERRORLEVEL%==0 ( echo Located - %SERVER%%%i >> %logfile% ) else ( echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile% ) ) endlocaltry this variables set and read inside parenthetical expressions need delayed expansion. setlocal enabledelayedexpansion set TIB=example.txt set SERVER=C: for /f "eol=; tokens=* delims=" %%i in (%TIB%) do ( dir "%SERVER%%%i" | find "wwwwwwww" >nul if !ERRORLEVEL! EQU 0 ( echo Located - %SERVER%%%i >> %logfile% ) else ( echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile% ) ) Thanks, not quite correct but you gave me a good pointer... I just needed to replace % with !... Code: [Select]if !ERRORLEVEL!==0 setlocal command was already added but not included it in my post above I've noticed another issue, but I'll create a new post Quote from: ShadyDave on April 29, 2010, 07:39:36 AM not quite correct Code: [Select]if !ERRORLEVEL!==0 Code: [Select]if !ERRORLEVEL! EQU 0 These two are equivalent; I don't understand why you call my VERSION "not quite correct". It created an error USING the EQU for some reason :-(Quote from: ShadyDave on April 29, 2010, 04:12:13 PM It created an error using the EQU for some reason :-(What was the line? If !ERRORLEVEL! EQU 0 echo There was no error... should work properly.Quote from: Helpmeh on April 29, 2010, 06:11:31 PM What was the line? It works properly for me. |
|
| 3430. |
Solve : Only copy folders? |
|
Answer» Is there a way just to copy a folder and all its subfolders but not the FILES in it???TRY using XCOPY with the /T and /E SWITCHES. This will copy the directory structure (including empty directories and sub-directories) without copying the files. |
|
| 3431. |
Solve : Batch file to move certain files+in sub folders? |
|
Answer» Hey, |
|
| 3432. |
Solve : Help create folders from a txt file including subdirs? |
|
Answer» Hi. I found a simple BATCH program that will create directorie/folders from a txt file (ie., LIST.txt). It looks like this: Thanks. That was a typo. My txt file has '\'. The problem is when you add a space in the name: 'folder 1\subfolder1'. The program will only create:'folder'. It's probably a simple solution of which i don't know 1. The default token delimiter in FOR /F is a space, so FOR will stop at the first space in each line of folders.txt. You must make FOR take the WHOLE line by USING "delims=". 2. In mkdir or any other operation where a file, folder or path name has one or more spaces, use quote marks. You can use them anyway, they do no harm. mkdir "A folder name with spaces" Code: [Select]@echo off for /f "delims=" %%i in (folders.txt) do mkdir "%%i" |
|
| 3433. |
Solve : DOS security password? |
|
Answer» oh my GOSH- I need help! I'm trying to HACK into my sons COMPUTER- he deleted or changed my administrator info/password somehow. If it is a laptop machine and whoever enabled a BIOS password your only choice is to take the laptop to an authorised service center in your area...wow. That is QUITE a bump. Anyway, I sure hope the original parent learned how to be a parent and talk to his kids instead of slinking AROUND in the shadows and talking about then like they are enemies. |
|
| 3434. |
Solve : netstat -an Help? |
|
Answer» When I type this in the run box on my XP machine it opens momentarily with a small list that shows what I am doing. Then fills with something else but closes out before I have time to read it. SEEMS suspicious ? THANKS R CTry it with opening the window with start/run cmd...instead of the command prompt,Thank you so much, it worked GREAT, not sure why but thats is OK !Now I would like to know what I am looking at. Can anyone tell me where to GO to learn about this list. ? |
|
| 3435. |
Solve : Check Network path exists? |
|
Answer» Hi everyone, 1. What is the nul for :- It's legacy code to indicate a directory and not a file. Don't think it's necessary on the more modern OSes. Quote 2. I tried to use the same code to check for a exists file :- I think control was passed to :evarscopied and then FELL into :copyevars. Normally goto is used without the : marker and the call is used with the : marker when calling an internal subroutine. Code: [Select]if exist C:\cae_prog\pdms\v11.6\CadCentre\mong_evars.bat (call :evarscopied) else (call :copyevars) . . . goto :eof :evarscopied . . . goto :eof :copyevars . . . goto :eof Before call :label came on the scene, I used to use goto for internal subroutines by setting a variable to a label name immediately following the goto. I could then use a goto to the variable (which held the label name); this allowed control to be returned to the next sequential instruction after the goto. Primitive yes, but in those days we learned to make do Good luck. Quote from: Sidewinder on April 20, 2010, 06:18:30 AM It's legacy code to indicate a directory and not a file. Don't think it's necessary on the more modern OSes.http://blogs.msdn.com/oldnewthing/archive/2003/10/22/55388.aspxHi almost got this working...one glitch is left the server name... If I was going to path my drive and folder in I would use :- net use Z: \\SAOSL10005.ALST.NO\TCM /PERSISTENT:NO I've tried this...to check the existance of the drive :- if exist \\Saosl10005.Alst.no\Tcm (goto :pathexists) else (goto :newpath) But it's not working... So what have I got wrong in my code.. Thanks NeilCode: [Select]If I was going to path my drive and folder in I would use :- net use Z: \\SAOSL10005.ALST.NO\TCM /PERSISTENT:NO What does "I would use" mean? Did you use net use or not? If the drive is mapped successfully, there is no reason for the exist test. Do you really want to use goto and not call? By using the : marker it makes it difficult to see what your trying to do. Based on your code, this might be simpler: Code: [Select]@echo off if exist Z:\nul goto :pathexists net use Z: \\SAOSL10005.ALST.NO\TCM /PERSISTENT:NO 1>NUL 2>NUL if errorlevel 1 goto :error if errorlevel 0 goto :pathexists :pathexists echo pathexists goto :eof :error echo error goto :eof Should you decide to use call instead of goto, the code may need to be tweaked. I wanted to check the for the full path :- Z: \\SAOSL10005.ALST.NO\TCM Just INCASE there was already a Z:\, but different path :- Z: \\SAOSL10006.ALST.NO\Files Cheers NeilThe path is either Z:\ or \\SAOSL10005.ALST.NO\TCM, the former being conventional notation, the latter using UNC notation. You can't use both, but you should be able to parse the net use output which will co-relate the local mapped drive to the remote device name. That should give you enough information as to whether the Z: drive is mapped and if so mapped correctly. Code: [Select]@echo off for /f "tokens=2-3" %%i in ('net use ^| find /i "Z:"') do ( if not errorlevel 1 ( set local=%%i set remote=%%j goto Mapped ) ) :UnMapped . . . goto :eof :Mapped echo Local drive: %local% echo Remote Drive: %remote% . . . goto :eof If drive Z: is not mapped, the logic will fall into the :UnMapped label. If drive Z: is mapped, the logic will leave the for LOOP and start executing at the :Mapped label. I'll let you fill in the blanks. The if statement in the for loop is written *censored*-backward. Unlike REXX for example, the nop instruction does not exist in batch code. NOP (no operation) is a GREAT target for conditional statements as it improves readability. Dare I say good luck? Quote from: Sidewinder on May 04, 2010, 07:09:51 PM The if statement in the for loop is written *censored*-backward. Unlike REXX for example, the nop instruction does not exist in batch code. NOP (no operation) is a great target for conditional statements as it improves readability. REXX is the only language aside assembly that has a NOP, as far as I know... |
|
| 3436. |
Solve : How to input the username and password on the script?? |
|
Answer» Dear all, |
|
| 3437. |
Solve : Batch File - Select the text within { and }? |
|
Answer» I'm looking to make a batch file for BitLocker and I need to COPY the GUID after running "manage-bde -protectors C: -get". The GUID is in the {} BRACKETS, so it would be somewhat easy to NARROW the TEXT SEARCH needed to that area. Another option would be to get the GUID directly and store it as a variable. |
|
| 3438. |
Solve : Missing something - option to tell it where to save? |
|
Answer» Hello. after the first pause put Thanks for your reply. However, when I added that, i get the following output: "The filename, directory name, or volume label SYNTAX is INCORRECT" after it tries creating the folders (mkdir). The command is written out like this: mkdir %dr%:\Backup_%mm%-%dd%-%yyyy%\Favoritesand what are you entering in the prompt given by set /p?Quote from: BC_Programmer on May 04, 2010, 08:02:48 PM and what are you entering in the prompt given by set /p? I've tried several different variations: i i: i:\ and they all return the same error(s) because it's trying to create 3 folders on the drive that I specifyyou have to enter a single letter. try echoing %dr%:\ after you enter it and see what it expands to. Additionally, I found a pretty neat course online that deals with writing a backup utility, and it served me as a great REFRESHER of batch scripting since I haven't done it in over ten years. It's put together pretty well but uses some old-school techniques. In any case, it was worth the few hours to me to go through it and adapt the program to my needs while (re)learning to write batch scripts. http://www.allenware.com/icsw/icswidx.htm |
|
| 3439. |
Solve : Using batch script to parse directories from a string? |
|
Answer» I'm writing a script that needs need to call a parameter from an EXECUTABLE's initialization file. I know where the executable is in this instance, but I'd like to write a reusable subroutine as I see this as a potential helpful TOOL. What I am after specifically would be the following: :EXPAND FILEPATH to parse Sounds like you should study the FOR DOCUMENTATION... type FOR /? at the prompt... Look for the variable modifiers. to extract the path from a fully qualified path and filename is quite simple Code: [Select]for /f "delims=" %%A in ("C:\folder1\folder2\folder3\filename.ext") do ( echo drive %~dA echo path %~pA echo name %~NA echo extension %~xA ) Code: [Select]drive C: path \folder1\folder2\folder3\ name filename extension .ext Quote from: Salmon Trout on May 05, 2010, 12:37:21 PM Sounds like you should study the FOR documentation... type FOR /? at the prompt... Look for the variable modifiers. |
|
| 3440. |
Solve : make long filename folders with makedir? |
|
Answer» Too many YEARS - too much forgotten. My batch file which use MD to create directories from a list of new folders have stopped working for some reason. It used to be that the command line |
|
| 3441. |
Solve : getting file size with space in folder...? |
|
Answer» I'm trying to get the FILE size of a file using the following code; Is it not possible to check file size where there is a space in the path? Yes it is. You have to STUFF the entire file name into a single variable either by ELIMINATING the space as the default delimiter or DECLARING a single variable with the spaces included: I chose the later: Code: [Select]@echo off for /f "TOKENS=*" %%i in ("\\server\snp_other_rsync\new folder\test.txt") do echo %%~zi Good luck. |
|
| 3442. |
Solve : batch file to open an antivirus program, update, run, close, then open another? |
|
Answer» scenario: Does anyone know if its possible to write a script to click OK automatically without having to physically click OK For the MBAM update popup you'll need to switch to a Windows script language (VBScript, JScript and Powershell 2 are already installed on your machine; others can be downloaded and installed) As mentioned I have no experience with Avast, so try playing around with the parameters until something accomplishes what you need. All three programs have help files which may explain more than the webs pages that were posted. |
|
| 3443. |
Solve : unable to eliminate a moving icon.? |
|
Answer» I AM NEW TO APPLE IMAC. THE LOADING ICON (DISC MOVING ROUND AND ROUND) NEVER STOPS AND DOES NOT LET ME CHOOSE A SUBJECT AS LONG AS IT IS MOVING. THE POINTER ALSO IS NOT ABLE TO BE USED TO POINT AT ANYTHING. |
|
| 3444. |
Solve : Limit extension search to 3 characters? |
|
Answer» Hello I have a reasonably simple problem using the FOR command. |
|
| 3445. |
Solve : At + run as admin? |
|
Answer» Hi there, As seen as I don't get a lot of response, i'll post what I allready succeeded in: http://www.windowsnetworking.com/kbase/WindowsTips/WindowsXP/AdminTips/Utilities/XPschtaskscommandlineutilityreplacesAT.exe.html C:\test>SCHTASKS /Create /TN runprogram /TR c:\windows\... /sc daily /sd 06/05/2010 SUCCESS: The scheduled task "runprogram" has successfully been created. sd format is month/day/year and not day/month/year might be the problem. C:\test>SCHTASKS /End /TN runprogram SUCCESS: The scheduled task "runprogram" has been terminated successfully. http://social.technet.microsoft.com/Forums/en/winserverManagement/thread/454b0e9e-1ef1-4026-a8e3-91766f049f91 Blackberry: maybe you can force it to run as the admin directly by using the /u and /p switches? (/u machine/administrator /p ) |
|
| 3446. |
Solve : son changed password in bios...? |
|
Answer» My son (15) wanted to change his password in command prompts (why I dont KNOW) and that somehow took him to the bios SCREEN where he changed it there...then after he couldnt log out he SHUT it down. The monitor will not come up it clicks LIKE it is turning off after about 30 seconds. We are using the MOTHERBOARD grafics card. Any suggestions about how I can get it to come up???It's always a kid... |
|
| 3447. |
Solve : Need batch file to delete dupes? |
|
Answer» The BATCH file will go through every sub-folder in a SPECIFIED folder, and delete the first version of any file that's the same length as another file in that folder. |
|
| 3448. |
Solve : Batch file - conditional backup upon startup? |
|
Answer» Quote from: The Raddish I do admit I do not fully understand the logic in the following command: You have to consider the whole line: Code: [Select]echo "!thisline!" | find "<setting id=""21"">" | find "</setting>" && goto foundline What's happening is this... We send !thisline! through a pipe to an instance of the find command*. The search string is "". The quotes around "21" need to be doubled to make them literal so that find will treat them as part of the search string. If that search string is present, all of !thisline! is output by find. If it is not present, there will be no output. Any output (including the null output if the string was not found) is conducted by another pipe to a second instance of find. This time the search string is "". If that string is also present in !thisline!, then two things happen. First, !thisline! is output (to the console)** by the second instance of find. Secondly, find returns an errorlevel of zero. If either the first or second string are not found, the errorlevel will be nonzero. The && double ampersand operator*** means "if the previous operation gave a zero errorlevel, then perform the operation immediately following." Thus only if both strings are found in !thisline! will the goto command be executed. * echo string1 | find string2 will echo string1 only if it contains string2. Find returns a zero errorlevel if the search string was found, and a nonzero errorlevel if it was not. If you only want the errorlevel and don't care to see the string, you can redirect the output to nul. ** to avoid screen clutter, I redirected the output of the second find to the null device with >nul but I see you have removed that. *** command1 && command2 ... EXECUTE command1 and if it is successful (i.e. returns a errorlevel of zero) execute command2 simple example dir cat.txt && echo There is a file called cat.txt in this folder Or echo %monthname% | find "December" && ( echo CHRISTMAS is coming! echo The goose is getting fat call Santa.bat ) The converse is the || (double pipe) operator operation1 || operation2 means execute command1 and if it "fails" (i.e. returns a nonzero errorlevel) execute command2. I must have read dozens of descriptions of how and what pipe does. I loosely understood the concept, but was thoroughly confused when it came to using multiple pipes in a single line. Your explanation in the above post was the most clear and and easy to understand description of how the pipe operator works that I have read to date. My hat's off to you, sir! I have another question, but I'll post a new thread for it. It's related to this script but is a good question in it's own right. Again, thank you for the time and effort you spend here educating others. Quote from: Salmon Trout on May 03, 2010, 12:28:27 PM SPECIAL characters need escaping: the escape for most is ^. To echo a string with < or > or both, quote it. To escape one quote, use another. Using the above as a model, mine looks like this: Code: [Select]@echo off setlocal EnableExtensions setlocal EnableDelayedExpansion set XMLFILE=C:\test\file.xml for /f "delims=" %%A in (%XMLFILE%) do ( set "THISLINE=%%A" echo "!THISLINE!" | find "<setting id=""21"">" | find "</setting>">nul && goto FOUNDLINE ) :FOUNDLINE for /f "tokens=1-3 delims=^<^>" %%A in ("!THISLINE!") do set RAW_PATH=%%C echo. %RAW_PATH% This works on my sample file, but I found that when deployed on another machine that has a larger XML file, I got the following error on four lines: Code: [Select]'#178' is not recognized as an internal or external command, operable program or batch file. '#178' is not recognized as an internal or external command, operable program or batch file. '#178' is not recognized as an internal or external command, operable program or batch file. '#178' is not recognized as an internal or external command, operable program or batch file. In searching the XML setup file on the other machine, there were four lines with #178 in them. So I copied those lines into a test file, and sure enough, the error appears when the batch script is run on the test file. It doesn't really affect anything other than displaying the error while parsing the XML file for the file path, but I'd like to understand why it triggers on these lines and if there is anything that can be done to correct it. sample file.xml: Code: [Select] <column data-type="9" description="" modifying-command="276" name="Solar_kW" process="" units="kW/m²"> <column data-type="9" description="" modifying-command="276" name="Solar_kJ" process="" units="kJ/m²"> <column data-type="7" description="Smp" modifying-command="0" name="Solar_kW" process="Smp" units="kW/m²"> <column data-type="7" description="Smp" modifying-command="0" name="Solar_kJ" process="Smp" units="kJ/m²"> <setting id="2">1</setting> <setting id="3">1</setting> <setting id="12">257149</setting> <setting id="15">1</setting> <setting id="16">2</setting> <setting id="17">%a\raw_data.dat</setting> <setting id="18">10</setting> <setting id="20">3</setting> <setting id="21">C:\Datalogger\raw_data.dat</setting> <setting id="22">0</setting> <setting id="23">30000</setting> <setting id="1" /> <setting id="2">0</setting> <setting id="3">2</setting> <setting id="12">9</setting> <setting id="15">1</setting> <setting id="16">2</setting> <setting id="17">%a\%s_%n.dat</setting> <setting id="18">10</setting> <setting id="20">3</setting> <setting id="21">C:\Datalogger\final_storage_2.dat</setting> <setting id="22">1</setting> <setting id="23">30000</setting> <setting id="28">3</setting> <setting id="30">6619599</setting> <setting id="31">3</setting> <setting id="2">1</setting> <setting id="14" /> <setting id="15">1</setting> <setting id="16">1</setting> <setting id="17">C:\Datalogger\ports_and_flags.dat</setting> <setting id="18">10</setting> <setting id="20">3</setting> <setting id="21">C:\Datalogger\Sifter\ports_and_flags.dat</setting> <setting id="22">1</setting> It's the ampersand before the #178 which is causing the error message. The ampersand is a well known "poison character". The command interpreter (cmd.exe) regards it as the command chaining character. echo hello & echo goodbye hello goodbye echo hello & goodbye hello 'goodbye' is not recognized as an internal or external command, operable program or batch file. Processing any string with any & characters will cause errors unless special precautions are taken. A workaround that I suggest is to replace the & with another harmless character e.g. an asterisk, before sending the line through SEND. @echo off setlocal EnableExtensions setlocal EnableDelayedExpansion set XMLFILE=C:\test\file.xml for /f "delims=" %%A in (%XMLFILE%) do ( set "THISLINE=%%A" set THISLINE=!THISLINE:^&=*! echo "!THISLINE!" | find "<setting id=""21"">" | find "</setting>">nul && goto FOUNDLINE ) :FOUNDLINE for /f "tokens=1-3 delims=^<^>" %%A in ("!THISLINE!") do set RAW_PATH=%%C echo. %RAW_PATH% Thanks once again, it works as expected! |
|
| 3449. |
Solve : Batch - Copy files with a same filename within a folder structure? |
|
Answer» Hey folks!
There are never two files with same name in the same folder.Are you still interested in this? I happen to be WORKING on a project which is related and might help you out. Pleas give more details on what you are trying to achieve. What type of files, etc...? [emailprotected]If understand this correctly, you have duplicate file names across a directory tree but now you want them in a single directory where duplicate file names can be a real problem. One solution would be to use XCOPY as a helper utility (use the /s switch to hunt down all the files in the tree, but also use the /l switch to not actually copy anything. Th end result will be a list of files that would have been copied which you can use in combination with an existence test and the plain old COPY utility. Along the way you can build a sequence number to add to the file name to prevent duplicates. A bit unconventional perhaps, but sound logic. Code: [Select]@echo off setlocal set source=i:\myFiles set target=c:\temp for /f "tokens=*" %%i in ('xcopy /s /e /l %source%\* %target%') do ( if exist %target%\%%~ni%%~xi (call :sequence %%i) else (copy "%%i" "%target%\%%~ni%%~xi" 1>nul 2>nul) ) goto :eof :sequence for /l %%x in (1,1,25) do ( if not exist "%target%\%~n1_%%x%~x1" ( copy "%%i" "%target%\%~n1_%%x%~x1" 1>nul 2>nul goto :eof ) ) goto :eof Be sure to set the source and target variables to valid values for your machine. The current script is set for a possible 25 duplicates for any single file name. Change as necessary. Good luck. |
|
| 3450. |
Solve : read file error in main routine? |
|
Answer» HI Guys I am having a problem with a machine that USES DOS 6.22. When I GO to run the progam on the machine I get an error "READ file in main routine" and then a C prompt. Any idea what this means. Sounds like a disk error but ... what program is it? Run from hard drive or floppy or what? Insufficient information. |
|