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.
| 3301. |
Solve : Batch file to create backup for a week? |
|
Answer» I have a backup file which gets generated everyday with the same file name "contentstore.zip" and gets stored in a specific location C:\contentstore_backups. So each day, the previous copy of the file is overwritten. I want to write a BAT file which renames the file contentstore.zip file to contentstore_currentdate.For instance, if today's date is 04/14/2009, then i want it to renamed as contentstore_20090414.use %date% or %time%. search the forum for examples on how to get date VALUES into variables. Quote However , after 7 days, I want the oldest file to get deleted , so that at a point I have only 7 backups in the folder "contentstore_backups".you can set scheduled tasks every 7 days to execute your batch file. use dir (and some of its OPTIONS) to list files according to time stamp. check the dir /? help for more info. you want something like: Code: [Select]for /f "delims=/ tokens=1-3" %%A in ('date /t') do ( ren C:\contentstore_backups\contentstore.zip contentstore_%%A%%B%%C.zip) The deleting after a week is a little more tricky. You might want to look at VB for that, and to be fair if you're going to look at VB for that you may as well do the whole thing in VB... FBThanks for the inputs. It really helped me with the first part of my problem--renaming of the file with the date in it The second part was: Now for instance, for the next seven days every day we get a new backup file: contentstore_20090414 ----taken on 04/14/2009 contentstore_20090415 ----taken on 04/15/2009 contentstore_20090416 ----taken on 04/16/2009 contentstore_20090417 ----taken on 04/17/2009 contentstore_20090418 ----taken on 04/18/2009 contentstore_20090419 ----taken on 04/19/2009 contentstore_20090420 ----taken on 04/20/2009 On the 8Th day, when we get a new file "contentstore_20090421" on 04/21/2009, I want the oldest backup "contentstore_20090414" taken on 04/14/2009 to get deleted. This ensures that I have only 7 backups at any given time. Since the files are named in this format, can we not sort the filenames and delete the file with the SMALLEST name? Quote from: em on April 14, 2009, 11:10:19 AM Thanks for the inputs. It really helped me with the first part of my problem--renaming of the file with the date in itHmmm... It looks possible with FOR...@OP, set a scheduled task to execute every 7 days. in your batch, you just specify dir ( with a for loop) to get the oldest file. check the dir/? for more info, or search the forum. (been posted many times). Quote from: gh0std0g74 on April 14, 2009, 07:40:42 PM @OP, set a scheduled task to execute every 7 days. in your batch, you just specify dir ( with a for loop) to get the oldest file. check the dir/? for more info, or search the forum. (been posted many times).Ok, set a sheduled task for this: Code: [Select]@echo off dir /b /o:d C:\contentstore_backups > directory set /p delzip=<directory del C:\contentstore_backups\%delzip% del directoryThat should do it.Code: [Select]@echo off pushd C:\contentstore_backups || goto:eof dir/b contentstore.zip || goto:eof >$$$.vbs echo wsh.quit year(date)*10000+month(date)*100+day(date) cscript//nologo $$$.vbs ren contentstore.zip contentstore_%errorlevel%.zip for /f "skip=7" %%a in ('dir/b/on contentstore_*.zip') do del %%a del $$$.vbs popd untestedQuote from: Reno on April 15, 2009, 01:44:05 AM Code: [Select]@echo offMine works for getting rid of the oldest one...as long as there isn't anything in the folder other than the .zips. The Code: [Select]@echo off dir /b /o:d C:\contentstore_backups > directory set /p delzip=<directory del C:\contentstore_backups\%delzip% del directory Echo Oldest file deleted. for /f "tokens=1-3 delims=/ " %%a in ("%date%") do ( set y=%%c set m=%%b set d=%%a echo %%a echo %%b echo %%c ) ren C:\contentstore_backup\contentstore.zip contentstore_%y%%m%%d%.zip echo Zip File has be renamed! You may now close. pauseA combo of my previous code (for deleting the oldest file) and my new one (which does the renaming).Batch Features:Quote from: Helpmeh on April 16, 2009, 05:58:14 AM Mine works for getting rid of the oldest one...as long as there isn't anything in the folder other than the .zips.Answer: Quote from: em on April 14, 2009, 08:49:36 AM However , after 7 days, I want the oldest file to get deleted , so that at a point I have only 7 backups in the folder "contentstore_backups". bug fix: for /f "skip=7" %%a in ('dir/b/o-n contentstore_*.zip') do del %%a looks like the OP didn't come BACK hereQuote from: Reno on April 17, 2009, 12:29:07 AM Batch Features:Answer:Wait...my code works fine, it deletes the oldest one, and then renames the undated zip to what the OP requested.helpmeh, it's logic error. imagine the batch first running, and initially there is only one file contentstore.zip dir /b /o:d C:\contentstore_backups > directory set /p delzip=<directory del C:\contentstore_backups\%delzip% bang, there it goes, today content_store.zip which should be renamed goes into dos black hole. ok, how about if the directory already contain 2,3, or even 4 contentstore_yyyymmdd.zip everytime the batch is run, the numbers of backup will never increase. thus the requierment of 7 backups at any time is not fulfil. the only condition where your batch will works is the folder only contain 8 *.zip file(s) -including the contentstore.zip to be renamed, not LESS, not MORE. and only contentstore*.zip, or else the batch code is buggy. and date retrieving problem, .......Quote from: Reno on April 18, 2009, 10:13:37 PM helpmeh, it's logic error.Oh...now I see. It could be fixed with a FOR loop (now that I know the basic functions of FOR, I love it)...I think. for /f "delims=" %%a in ("directory") do ( set /a loop+=1 ) That should count how many lines are in directory, and... if %loop%==8 del C:\contentstore_backups\%delzip% So the full (hopefully) working code is: Code: [Select]@echo off dir /b /o:d C:\contentstore_backups > directory set /p delzip=<directory for /f "delims=" %%a in ("directory") do ( set /a loop+=1 ) if %loop%==8 del C:\contentstore_backups\%delzip% del directory Echo Oldest file deleted. for /f "tokens=1-3 delims=/ " %%a in ("%date%") do ( set y=%%c set m=%%b set d=%%a ) ren C:\contentstore_backup\contentstore.zip contentstore_%y%%m%%d%.zip echo Zip File has be renamed! You may now close. pauseThat should work...as long as FOR counts the lines... |
|
| 3302. |
Solve : Is it possible to write simple text files with batch?? |
|
Answer» I know i can use the echo command to write something but that will enable me to write something with only one line, unless i use && or ^& but THATS only for if i'm WRITING ANOTHER batch file. (that's the 4 line equivilent of what can be done in 2 (or 1). echo hello > a.txt echo world >> a.txt or echo hello > a.txt & echo world >> a.txtlike Helpmeh, you can move ">" to begin of your command. > a.txt echo hello >>a.txt echo world >>a.txt echo does this work? Quote from: tonlo on April 19, 2009, 08:49:06 AM like Helpmeh, you can move ">" to begin of your command.I have never tried it that way... |
|
| 3303. |
Solve : calling same batch file within second batch file multiple times? |
|
Answer» I want to write a batch file that calls a second batch file mutiple times. Each time the second batch file is called I need to pass different parameters. |
|
| 3304. |
Solve : Renaming a File to INCLUDE BOTH Date & Time Stamp? |
|
Answer» Quote Several times a day, you want to backup a file C:\folder1\catalog.MDB to C:\folder2\catalog <timestamp>.mdb. The FOLLOWING script in biterscripting ( http://www.biterscripting.com/install.html - it is free) will do the job. Code: [Select]system copy "C:\folder1\catalog.mdb" ("\"C:\folder2\catalog "+gettime()+".mdb\"") Come to THINK of it, there is only one line in this script. J |
|
| 3305. |
Solve : several DOS questions? |
|
Answer» Why do I get the feeling this is going to be a long one? I don't think cd is an alias of something else, as it works fine until this I:\program_files case. chdir works same as cd weird, because on my computer I can cd to any directory regardless of the name. I think the fact that it is attached to a Linux server via NFS is extremely relevant. But I'm not to experienced with Linux Filesystems.Quote from: lehe on April 18, 2009, 12:06:33 PM I am not sure it is related that my disk is attached to a linux server via Network File System. Now he tells us yeah I am not sure if NFS is the issue. The same thing also happen on my LOCAL disk C. I.e., if I create C:\program_files, cd cannot change to it. Also cd can work for a directory like C:\t_e but not for a directory like C:\eeeeeee_fffff. Quote from: lehe on April 18, 2009, 12:28:49 PM I am not sure if NFS is the issue. The same thing also happen on my local disk C. I.e., if I create C:\program_files, cd cannot change to it. Also cd can work for a directory like C:\t_e but not for a directory like C:\eeeeeee_fffff. Are you using command or cmd? I am using command. Yeah, changing to cmd solve the problem! So cmd is not DOS but command is?Quote from: lehe on April 18, 2009, 12:50:48 PM I am using command. At last. Squall noticed this first. CMD.EXE is a 32 bit program. It's what you get when you select Command Prompt on the Windows Accessories MENU. COMMAND.COM, on the other hand, exists only for compatibility and 16bit programs. It exists solely for those programs which have not been UPDATED since the days of MS-DOS. It's designed to run 16bit applications, and operates just like the old MS-DOS did.In short- use cmd.couldnt he go to start - accesories - cmd and work it just the same? |
|
| 3306. |
Solve : substring question? |
|
Answer» Within a Windows XP batch file I NEED to find a substring within a variable string and then do something if it is equal or not equal. Find and FindStr seem to only work with files so I was wondering just how to do this with a variable in an if statement. Hi, reno It is a small relative of your %%G Quote from: Geek-9pm on April 18, 2009, 11:34:22 PM Hi, renoQuote from: Z.K. on April 18, 2009, 07:00:19 PM if %%G contains "command" (there is indention in the above code, i assume he is inside a for loop, %%g refers to token variable. besides for loop, i can't think anywhere else in coding a %%g can be used. Code: [Select]for /f "tokens=1*" %%f in (sometextfile.txt) do ( echo %%g|find "command" >nul 2>&1 && echo a message ) example text file: this is a command sample output: c:>\test.bat a message for complete explanation, type for/?Thanks, It said: To use the FOR command in a batch program, specify %%variable instead of %variable. Variable NAMES are case sensitive, so %i is different from %I. It also said the variable is onl a single LETTER. |
|
| 3307. |
Solve : Non-Looping For Loop? |
|
Answer» I am trying to make get a user to log in, so they can continue using the batch SCRIPT, but the login is failing in the second FOR loop... I have no idea. The second FOR loop requires the first FOR loop (which does work) to calculate the amount of lines...so I can't really break it up. But I know what the problem is. It just does the first line, and then does nothing else. for /f "tokens=1-2 delims= " %%a in ('type %fname%') do ( if "%%a"=="%usr" if "%%b"=="%pass%" goto cont set /a num2+=1 if %num2%==%num1% cls & echo Username and/or password don't match. & goto looplog ) :cont echo HI! pauseCode: [Select]@echo off setlocal enabledelayedexpansion set fname=list.txt :looplog set num1=0 set num2=0 echo Enter your username. set /p usr=Username: Echo Enter your password. set /p pass=Password: pause for /f "delims=" %%z in ('type %fname%') do ( set /a num1+=1 ) echo Lines: %num1% pause for /f "tokens=1-2 delims= " %%a in ('type %fname%') do ( if "%%a"=="%usr%" ( if "%%b"=="%pass%" ( goto :cont ) ) set /a num2+=1 if !num2!==!num1! ( cls echo Username and/or password don't match. goto :looplog ) ) :cont echo HI^^! pauseQuote from: Batcher on April 19, 2009, 09:19:33 PM Code: [Select]@echo offThanks! |
|
| 3308. |
Solve : query software? |
|
Answer» I have SCRIPT that will let you know all of software installed in your local machine by searching the key in your register. Not every OS allow remote operation registry. If you need run the command like reg query \\xxx.xxx.xxx.xxx\..., please make sure the service Remote Registry is started on the remote OS. Many thank you, Batcher, how can i forgot the services |
|
| 3309. |
Solve : Shutdown Command to use in DOS? |
|
Answer» I don't see how that enters into the mix at all. I don't see how that enters into the mix at all.The ping makes the batch WAIT for one second before continuing...just incase your program takes a bit of time to close.Well, I just finished testing the DOS Shutdown program and it works a treat. I'll post the link when I have more time to upload the zip file to my FTP Server. Probably tomorrow. Shadow Quote from: TheShadow on April 29, 2009, 08:39:31 PM Well, I just finished testing the DOS Shutdown program and it works a treat.You can just upload the zip here...Well, I just cleaned up the Instruction text file and re-compressed the files into a self extracting zip file, using 7Zip. The file "Shutdown DOS.exe" can be downloaded here: http://www.box.net/shared/fcc6cam8x8 I thank everyone who has tried to help me with this little problem. Cheers Mates! Shadow Thanx again Shadow !Did Shadow ever consider a hybrid method? Perhaps Hardware modification and a small bit of software to force a machine to shut down could do the JOB. The DOS Shutdown.com program works a treat. Nothing else is required. Try it.........you'll like it. |
|
| 3310. |
Solve : How to check condition in txt file? |
|
Answer» Quote from: Salmon Trout on November 17, 2009, 03:19:26 PM But 1st December SATISFIES LEQ 30th November; and I see trouble ahead if the day NUMBER has a leading ZERO. I guess we'll find out in a fortnight. Yogesh123 is comparing only the first 25 days of any month. Yogesh123 does not compare Dec 1 with Nov 30. It is POSSIBLE 01 could be considered an octal number? Is octal 1 > 25?Quote from: billrich on November 17, 2009, 04:09:10 PM Yogesh123 is comparing only the first 25 days of any month.so what if he doesn't do that now? When you write code, write it in such a way that it won't break when things happen. Its called code resiliency , by yours truly. Quote from: gh0std0g74 on November 17, 2009, 04:58:33 PM so what if he doesn't do that now? When you write code, write it in such a way that it won't break easily when things happen. Its called code resiliency , by yours truly. |
|
| 3311. |
Solve : Opening files from list of files? |
|
Answer» Gudday all The file is 20090619153310.SPL No other files are parsed. I have 'remed' out the seemingly offending lines in the code above. Also is it possible to pass a variable, in this case %%a, from the inner loop to the outer loop? I wanted the progarm to tell me when it finished each file. The line ' left loop after 1st line of the file' is printed but not the current file name. You can use set /p to get the first line of a file. SET /P variable= It works because by default SET with the /p switch waits for a CR terminated string from STDIN (the keyboard) however you can use the < redirection symbol to make it take its input from a file. The crlf at the end of the first line of a text file ensures that the command terminates. so this should work... Code: [Select]@echo off setlocal enabledelayedexpansion dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt for /f %%a in (SPLfiles.txt) do ( set file=%%a echo the file is !file! set /p firstline=<"%%a" for /f "tokens=1,2 delims= " %%i in ("!firstline!") do ( echo variable i = %%i echo variable j = %%j ) ) notes... (1) labels, GOTO etc In many ways, NT command script language is a kludge, and it doesn't always work the way you would expect if you are used to "proper" programming or scripting languages and tools. One thing that is peculiar is the way it processes loops and other parenthetical structures. A loop is processed as if it was one logical line. Thus this for [whatever] do ( some stuff ) is equivalent logically to for [whatever] do (some stuff) (In fact if you only have one command in the loop you can use that format.) Now you cannot have a label in the middle of a line, it has to be on a line by itself, so labels in loops break the code. Since your outer and inner loop is processed as one HUGE line, that is why it halted. Jumping out of loops is very tricky. While I am on the topic, you may come across example scripts where the writer has used a double (or SINGLE) colon instead of REM to start a comment line :: This is a comment This is a carryover from MS-DOS where the practice did no harm (I think). It works because labels are disregarded (mostly!) and the line is a (broken) label. However such a line inside parentheses BREAKS THE CODE. It is an undocumented and unsupported "feature". The behaviour it CAUSES can give much puzzlement to coders, however it is often vociferously defended by people who ought to know better. My advice is, don't do it! (2) Considering the FOR command, for /f %%V in (dataset) do With the /f switch, dataset (unquoted) is processed as a filename, whereas "dataset" is a string, which is why I used ("!firstline!") above. (3) In the other thread you asked about reference material for NT command scripting. One good site I have found is http://ss64.com/nt/ You may have the compiled help file ntcmds.chm on your system; it is not included on Vista & 7 I believe. type hh ntcmds.chm at the prompt to find out. If you don't have it, you can get if off an XP disk or installation, or download it from Microsoft (it is included in the Server 2003 Adminpak) http://support.microsoft.com/kb/304718 Dear ST Thank you once again. After some fiddling the code works at last! At least the boss is happy. |
|
| 3312. |
Solve : Read Characters from filename and move the file to a subfolder? |
|
Answer» HI, I need to read a filename and based on some characters, DECIDE to move the file in appropriate folders. Here is an example: gibberish_Water_Cloud.abc gibb_Water_Sky.abc moregibb_Air_Sky.abc stillmorgib_Air_Cloud.abc I need to move these into following four folders that ALREADY EXIST: Water_Cloud Water_Sky Air_Sky Air_Cloud Any help will be appreciated. Thanks This should help, make sure you put it in the same folder as the abc files. Code: [Select]@echo off for /f %%a in (*Water_Cloud.abc) do move %%a Water_Cloud\%%a for /f %%a in (*Water_Sky.abc) do move %%a Water_Sky\%%a for /f %%a in (*Air_Sky.abc) do move %%a Air_Sky\%%a for /f %%a in (*Air_Cloud.abc) do move %%a Air_Cloud\%%a Hope this helps ,Nick(macdad-)no need to use the for loop. Code: [Select]move *Water_Sky Water_Sky Oh well...EITHER worksyes, either works. but .............. |
|
| 3313. |
Solve : Need Help with Batch. Copy from source to dest, rename if exist.? |
|
Answer» Hi, the file1.txt (from DEST\subfolder1\subfolder2\) will be rename to file1.txt.bak, THEN file1.txt (from SRC\subfolder1\subfolder2\) will be copy to location DEST\subfolder1\subfolder2\this is your original question ANYWAY, this only works on single folder (not working on getting 2,3 or 4 level directories) set SUBDIR=%%~nxp -- x SWITCH in case you have extension on foldername and type for/? and look at the bottom for more information on available switches. untested, already late, i can't get my brain working right set subdir=%%p set subdir=!subdir:%src%\=! echo !subdir! Yea, i'm actually need multiple levels of folder support.. something like below: SRC\subfolder1\...\subfolderN ... SRC\subfolderN\...\subfolderN DEST\subfolder1\...\subfolderN ... DEST\subfolderN\...\subfolderN Thanksok, battery in full charge, brain in full working condition Code: [Select]@echo off & setlocal enabledelayedexpansion set SRC=C:\main folder\ set DEST=E:\main folder\ if not exist %dest% md %dest% for /r "%src%" %%a in (*) do ( set d=%%~dpa set d=%dest%!d:%src%=! echo %%a --^> !d! if exist "!d!%%~nxa" move "!d!%%~nxa" "%%~nxa.bak" && echo ren - %%~nxa.bak if not exist "!d!" md "!d!" && echo md - !d! copy "%%a" "!d!" >nul && echo copy - %%~nxa REM xcopy can auto create subdir, replacing the above 2 lines, but slower in execution ?? REM xcopy/i "%%a" "!d!" >nul && echo xcopy- %%~nxa ) Many thanks! the code was almost working! currently, all .bak goes to where the batch file is located, is it possible to leave the .bak files in the same directory it was from? e.g. if textfile.txt already exisit in DEST, after running the batch, DEST will be: DEST=E:\main folder\folder1\folder2\textfile.txt <---new file copied from source DEST=E:\main folder\folder1\folder2\textfile.txt.bak <---old file originally from dest Thanks again!!bug fix: replace this line: if exist "!d!%%~nxa" move "!d!%%~nxa" "%%~nxa.bak" && echo ren - %%~nxa.bak to if exist "!d!%%~nxa" move "!d!%%~nxa" "!d!%%~nxa.bak" && echo ren - %%~nxa.bak it's perfect! thanks for all the help! |
|
| 3314. |
Solve : Writing to a CSV file using a batch process.? |
|
Answer» I want to create and write data to a CSV file from within a batch PROCESS for one of my ongoing projects. Can ANYBODY help me in this? I am very new to writing batch FILES and it WOULD be really great if anyone can provide me with the code.first you head down to here to learn how to do batch files. then come here if you encounter problems. |
|
| 3315. |
Solve : batch check codition & echo? |
|
Answer» Dear Experts, strDateTimeInFile = CDate( dy & " " & mth & " " & theyr) &" "&CDate( hr & ":" & min & ":" & sec ) Why use CDate and String concat? You could use DateSerial and TimeSerial; also, this will allow for the return type to be a Date, rather then a string. (although I imagine type coercion is making everything work as it is; you can never really be sure in different locales) Code: [Select] DateTimeInFile= DateSerial(theyr,mth,dy)+TimeSerial(hr,min,sec) OLE automation Dates are stored as "double" types; "1" is one day after the origin (I can't recall, I think it was in the 1700's or something); times are represented as fractional portions. Therefore, we can add a TimeSerial to a DateSerial to create an entire TimeStamp. Quote from: Yogesh123 on November 17, 2009, 02:06:24 AM Can it be done using batch dos commands? You'll probably have to hope Salmon Trout or one of the other Batch Experts decides to tackle this one if you want a batch solution. Quote from: BC_Programmer on November 17, 2009, 02:09:50 AM nice heh, i had always wanted to try using these 2 functions, but never really got to it. CDate is what i am familiar with so i just wrote the script without MUCH thinking. But good call though. Quote from: Yogesh123 on November 17, 2009, 02:06:24 AM beacause i am not more concern about date comparison, comparison parameter could be no's also.why do you say its not about date comparison? didn't you say you need the 6th token to be LEQ current time or something.?? If it is, then IT IS date comparison. Unless your date format in the file is formatted to become like this YYYYMMDDHHMMSS, then it may be possible for comparison. (but still you need to format the current time and date also ), which is too much of a hassle to do in batch. Its time to move on.Quote from: gh0std0g74 on November 17, 2009, 02:22:57 AM heh, i had always wanted to try using these 2 functions, but never really got to it. CDate is what i am familiar with so i just wrote the script without much thinking. But good call though. Basically, when dealing with Dates, I've always found it works best to have everything as a date, rather then a string, always best to avoid Locale issues. Although as you said you whipped it up without thinking and it is definitely possible to over-analyze any approach @echo off setlocal enable delayed expansio for /f "tokens=1-7" %%a in (file.txt) do ( set tme1=!time::=! set tme2=%%f set tme2=!tme2::=! if !tme2! LEQ !tme1! echo %%a %%b %%c %%d %%e %%f %%g >> output.txt ) Untested, might not work, but it will at least point you in the right direction. Yogesh - try this. It is dependent on your %time% format being hh:mm:ss.ms, no allowance is made for AM or PM if that is included in the format. If you use the %1 variable for testing purposes it must be entered in the full format as above. The script is untested. Code: [Select]@echo off>output.txt setlocal enabledelayedexpansion :: set time=%1 set time=%time::=% set time=%time:~0,6% for /f "delims=*" %%1 in (abc.txt) do ( set line=%%1 for /f "tokens=1-6" %%2 in ("!line!") do ( set filetime=%%7 set filetime=!filetime::=! if !filetime! leq !time! echo %%1>>output.txt ) ) type output.txt No doubt one of the scripting gurus will COME up with something much more efficient. Good luck.We must use: setlocal enabledelayedexpansion Use !LD! not %LD% Salmon Trout provided this INFO a day or so ago rem I remarked set Ct=%time% out for a better test. Remove set Ctt=08 and the rem's in the code C:\batch>cat yo3.bat Code: [Select]rem set Ct=%time% rem echo Ct = %Ct% rem set Ctt=%Ct:~0,2% set Ctt=08 echo Ctt = %Ctt% @echo off setlocal enabledelayedexpansion for /f "tokens=1-7" %%i in (abc5.txt) do ( set LD=%%n echo LD=!LD! set LDD=!LD:~0,2! echo LDD=!LDD! echo LDD less or equal Ctt if !LDD! LEQ !Ctt! ( echo %%i %%j %%k %%l %%m %%n %%o ) else ( echo. echo No result found echo. ) OUTPUT: C:\batch> yo3.bat Ctt = 08 LD=12:00:57 LDD=12 LDD less or equal Ctt No result found LD=10:02:11 LDD=10 LDD less or equal Ctt No result found LD=11:02:12 LDD=11 LDD less or equal Ctt No result found LD=09:05:38 LDD=09 LDD less or equal Ctt No result found LD=05:06:13 LDD=05 LDD less or equal Ctt wsx.rfv 2 W0132017 Nov 26 05:06:13 2009 LD=07:06:33 LDD=07 LDD less or equal Ctt xdr.cft 0 W0132017 Nov 16 07:06:33 2009 LD=12:15:01 LDD=12 LDD less or equal Ctt No result found C:\batch> |
|
| 3316. |
Solve : findstr get different offset of the same string? |
|
Answer» Below is my batch script. C:\Test>test.bat Anybody can help me out? ------------------------------------------------------------------------------ [Update 2009-04-20 07:30:20 AM] I FIND a new clue. Save below code as a batch file. Code: [Select](echo TestStr&echo.)|findstr /o ".*" pause Run it, get below result. Quote C:\Test>(echo TestStr & echo.) | findstr /o ".*" One strange thing should be pointed out. The Command Line Interpreter adds 2 blanks before &. But generally, the command separator is only 1 blank. To see the duplicate blank in another way, let's run below command. Code: [Select](echo TestStr&echo.)|findstr /o ".*">a.txt We'll find there is a blank at the end of TestStr in the file a.txt. Why the Interpreter adds 2 blanks before &? Need help for further investigation. what is the actual problem you are trying to solve?Quote from: gh0std0g74 on April 19, 2009, 08:52:26 PM what is the actual problem you are trying to solve?Thanks for your quick reply. I find this question when calculating the length of a string. Actually, I know how to get the length of a string. Here we go. Code: [Select]@echo off rem character offset in command line for /f "tokens=1 delims=:" %%a in ('^(echo TestStr^&echo.^)^|findstr /o ".*"') do ( set /a StrLen1=%%a-3 ) echo %StrLen1% rem character offset in file echo TestStr>a.txt echo.>>a.txt for /f "tokens=1 delims=:" %%a in ('findstr /o ".*" a.txt') do ( set /a StrLen2=%%a-2 ) echo %StrLen2% I just interested in why the offsets are different, as mentioned in the topic.there is this invisible character for each new line, costing 2 bytes. - 0x0d 0x0a Code: [Select]C:\>(echo teststr&echo.)>a.txt C:\>dir a.txt|find "a.txt" 20/04/2009 11:59 11 a.txt 11 bytes - (2bytes*2lines) = 7 character Code: [Select]C:\>findstr/on ".*" a.txt 1:0:teststr 2:9: offset 9 - (2bytes*(2-1)lines) = 7 character (disregard the CrLf of last line) a.txt contents: Code: [Select]C:\>(echo.d100 10a & echo.q)|debug a.txt -d100 10a 0B20:0100 74 65 73 74 73 74 72 0D-0A 0D 0A teststr.... -q echo + findstr Code: [Select]C:\>(echo.teststr&echo.&echo hello)|findstr/on ".*" 1:0:teststr 2:10: 3:13:hellofor the above code, i've no idea why each new line cost 3 bytes Quote there is this invisible character for each new line, costing 2 bytes. - 0x0d 0x0aGood Grief! we have traveled in time back to 1979 when a programmer discovers that Intel® systems differ from UNIX system. Intel® uses two chars to end a line because of the prevalence of Model 23 TeleType® machines then being used for development on 8080 CPUs using Isis II. nowadays UNIX systems can run on Intel machines. Now It's an OS specific NEWLINE character that has been discussed before. Windows/DOS: CRLF (ASCII 13, ASCII 10) UNIX/LINUX: LF (ASCII 10) MAC: CR (ASCII 13)In 1979 Intel and others provided 8080 development systems that were not UNIX and used the two chars to end a line. You could send a text file to the TeleType machine.Can't do hat with just a line feed. And in Intel based system it has been that way, because Intel said so, not because of anything about the CPU. And years later when MANY started to use UNIX on Intel CPUs it confused the programmers. Not the fault of the CPU, it was not the Intel way. It was a question of what system you learned on. And old habits die hard. We still use two chars to end the line, but I doubt very much anybody is using any teletype machines nowadays. Mine worked better If I set up three nulls after Lin feed. The output thing would send nulls, if told to do so. I don't miss it one bit. Excuse the pun.Quote from: Reno on April 19, 2009, 11:02:58 PM there is this invisible character for each new line, costing 2 bytes. - 0x0d 0x0a Yes, I knew the eol (end of line) comment character 0D (CR) 0A (LF). Why it costs 3 bytes in my first scenario? Let's wait for the answer together : )Three bytes? in the command line there is a space in front of the first item. Could that be it?Quote from: Geek-9pm on April 20, 2009, 01:22:35 AM Three bytes? in the command line there is a space in front of the first item. Could that be it? I'm afraid not. Because I find a new clue. Save below code as a batch file. Code: [Select](echo TestStr&echo.)|findstr /o ".*" pause Run it, get below result. Quote C:\Test>(echo TestStr & echo.) | findstr /o ".*" One strange thing should be pointed out. The Command Line Interpreter adds 2 blanks before &. But generally, the command separator is only 1 blank. To see the duplicate blank in another way, let's run below command. Code: [Select](echo TestStr&echo.)|findstr /o ".*">a.txt We'll find there is a blank at the end of TestStr in the file a.txt. Why the Interpreter adds 2 blanks before &? Need help for further investigation. I am going to update above info in the topic. |
|
| 3317. |
Solve : Batch file & choices? |
|
Answer» I'm new to this level of programing so forgive me if any of this is stupid. I'm trying to write a batch file that reads from a SPREAD sheet and does something based on an input. Thanks for the code shortening.Good for you. I'm glad you made your own way. |
|
| 3318. |
Solve : Possible to Network? |
|
Answer» I have all these nics and thought about putting one into my 486. Thing is can I make it so that it is on a network or do I have to use something like novell or some KIND of NETWORKING os like that.you need the network drivers for the CARD. If the 486 has DOS you should select a NIC that has DOS drivers. |
|
| 3319. |
Solve : How to check task manager process status? |
|
Answer» Dear Experts, |
|
| 3320. |
Solve : VBS to EXE? |
|
Answer» HELLO! I have a file that i need to save as an exe so it can not be edited at or and/or so users are not getting our passwords... i have been searching for some time now and cannot find freeware that will let me convert and ALSO append an icon... does anyone know of any free software that will let me perform these tasks? Thanks for the assistance! HoFLFrom your information iut is hard to understand what you want to do. Do you intend to prevent the use of VBS to PROTECT your system? Dio you have a script that must be PROTECTED? Is the script part of a web page? Can you program in another language instead of VBS? I want to convert the following script into an ".exe" file. I just cannot seem to find a free app that actually works. One of the takes i need to be able to do is append an icon to the newly created ".exe". CODE: [Select]Dim WshShell Set WshShell = CreateObject("WScript.Shell") WshShell.run ("runas /env /user:administrator fluidpower.exe") WScript.Sleep (100) WshShell.AppActivate "C:\windows\system32\runas.exe" WScript.Sleep (100) WshShell.SendKeys "password" WScript.Sleep (100) WshShell.Sendkeys "~" WScript.Sleep (100) Thanks for he help! HoFL |
|
| 3321. |
Solve : batch file not working? |
|
Answer» hi i GOT a code earlyer and i edited it a bit well alot and its not working if anoyone can spot the problen plz reply Items in red are my replacements.That should do it.Quote if not "%pass%"=="password goto incorrect Spot the error Also: Quote echo plase type password This is how you spell "please". Quote echo you have used up all your trys system is shutting down The plural of try is tries. Quote from: Dias de verano on April 19, 2009, 01:15:33 PM Spot the errorLol...I can't believe I missed that...this is so wrong, if you try to password-protect your pc with batch and put the batch file in startup folder, it's the most silly thing i've ever heard. cmd batch run in a seperate process, in it's own box. To terminate it, i just need to press Ctrl-C or click on the X mark to close the box or just do nothing. plz use the built-in user account: Start-->Control panel-->user accountQuote Quote If BATCH is lexicographically sensitive, - I better give it up altogether yea but my dad my mum and my brother dont know that and any way the peice of code isent finished also i found somin else changes in red Code: [Select] @echo off set try=3 cd "%userprofile%" echo. >> log.txt echo Logged In>> Log.txt echo %userprofile% >> Log.txt echo %Date% %time% >> Log.txt goto start :fail cd "%userprofile%" echo. >> log.txt echo password incorrect>> log.txt echo %userprofile% >> log.txt echo %date% %time% >> log.txt echo password attempts left %try% >> log.txt :start echo plase type password [color=red]set /p "pass=>" [/color] if not "%pass%"=="password goto incorrect :stop cd "%userprofile%" echo __________>> log.txt echo password correct pause exit :incorrect if %try%==0 goto shutdown set /a try-=1 echo you have %try% tries left before shutdown pause goto fail :shutdown echo you have used up all your trys system is shutting down shutdown -s -f -t 10 cd "%userprofile%" echo. >> log.txt echo all atempts used>> log.txt echo shutdown at %date% %time%>> log.txt echo reason: password incorrect 3 times>> log.txt echo __________> log.txt exit thanks for your helpQuote if not "%pass%"=="password goto incorrect there is a quote mark missing at the end of "password This will cause a syntax error. Quote from: steven32collins on April 20, 2009, 09:17:54 AM also i found somin elseThe quotes shouldn't be required. Please not that you must escape the greater than character (as I did in a previous post).Quote from: Helpmeh on April 20, 2009, 03:14:06 PM The quotes shouldn't be required. Please not that you must escape the greater than character (as I did in a previous post). Either no quotes at all or two sets. One set no good. Quote from: Dias de verano on April 20, 2009, 03:44:21 PM Either no quotes at all or two sets. One set no good.I was talking about set /p "pass=>" is his code. This is what needs to be done: set /p pass=^> |
|
| 3322. |
Solve : Decypher file attribute in a FOR loop? |
|
Answer» My tests on the attribute variable seemed to work but I will give your suggestion a try. I am creating two dates in the format yyyyddd. I start by taking the year and multiplying by 1000 You may find these SCRIPTS useful http://www.commandline.co.uk/cmdfuncs/dandt/index.html Also, VBscript has built in date MATH functions. You can USE them from batch, if VBscripts are allowed on your system Code: [Select]@echo off REM Create VBscript echo wsh.echo Year(wscript.arguments(0))^&DatePart("y", wscript.arguments(0))>Daynumber.vbs REM now you can use it in your script as many times as you want set querydate1=20/11/2009 REM pass the date to the VBscript & get back the result for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate1%') do set Daynumber1=%%D set querydate2=20/03/2009 for /f "delims==" %%D in ('cscript //nologo Daynumber.vbs %querydate2%') do set Daynumber2=%%D echo The day number of %querydate1% is %Daynumber1% echo The day number of %querydate2% is %Daynumber2% output Code: [Select]The day number of 20/11/2009 is 2009324 The day number of 20/03/2009 is 200979 As you can see, my system uses the European dd/mm/yyyy format for dates but I believe that if your system locale settings are US you would find that 11/19/2009 would give you 2009323 but you would have to try that yourself. Hello |
|
| 3323. |
Solve : config parser in perl? |
|
Answer» Hello every one thanks for reply , i tried to play with that module.if it doesn't suit your needs, search CPAN for Parser or Config (or other search terms) and see if you can find others that's suitable for you. |
|
| 3324. |
Solve : Opening explorer.exe? |
|
Answer» If i was to open explorer.exe is there anyway to switch between to two interfaces??? so for instance have my music on 1 and my work on the other. i understand this would slow down my computer but it would be great to know dam, i was hoping for an inbuilt solution, thanks anyway guyz I take it you don't have admin rights and aren't allowed to install anything. Sounds like Google may have been correct. What are you trying to hide? You can have 2 Explorer WINDOWS open and tile them vertically. Or there are various free Explorer substitutes with multi pane layout options such as xplorer² Quote from: Salmon Trout on November 19, 2009, 12:39:12 AM You can have 2 Explorer windows open and tile them vertically. HAHAHAHa yea actuallly how could I have been so ignorant to not think of this?!?!? Nice Actually i am doing this at work and have admin rights as i am in ITbtw that picture is blank, are you talking about 2 folder explorers or actual user interface explorers Quote from: Khasiar on November 19, 2009, 05:39:59 PM btw that picture is blank, are you talking about 2 folder explorers or actual user interface explorersThe picture is definately not blank, and to answer your question, it is of 2 folders open beside each other. Quote from: Khasiar on November 19, 2009, 05:39:59 PM btw that picture is blank, are you talking about 2 folder explorers or actual user interface explorers Maybe PHOTOBUCKET is blocked where you are viewing this forum? 2 instances of Windows Explorer. I am not sure what this means: " 2 folder explorers or actual user interface explorers"Quote from: Khasiar on November 19, 2009, 05:38:49 PM Actually i am doing this at work and have admin rights as i am in IT Is there any reason you can't download and install the desktop manager I provided the link to? Since you are in "IT" I will wait for you to figure out what vital information you have left out in all of this.Windows Explorer handles both the windows desktop and the "folder explorers" more precisely, Explorer windows. I believe that Windows Explorer only allows one "desktop" windows explorer to run WITHIN each desktop. If one is already running, it opens a Explorer Window instead. Short story: if you want two DESKTOPS, you'll need a multiple desktop solution, such as that already provided. I've always rather liked the SysInternals "Desktops" program: http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx added advantage is that it works on Vista And windows 7... I think. |
|
| 3325. |
Solve : Help about ms-dos? |
|
Answer» Respected sir, My solution:do you think that other PC needs to have same hardware?I wouldn't think so- but some drivers in config.sys might not load. Worst case scenario being F5 to skip the two files. the "basic" DOS system will run on any PC- getting the extras (like sound and VESA support) are the tough ones.if it does work like bring the HDD to another PC and install XP, it would cause problems when its put back into the original PC. Is windows smart enough to "reconfigure" itself on different hardware ?oh. Nevermind- we're talking windows here. Nope- that won't work unless the PCs are similar. Although, in the case windows won't load (wrong Hal and drivers and such), then sometimes a Repair install can get it booting again. It would still have the wrong drivers and likely start using the generic ones, but it would be enough to start and install the proper ones. I found something interserting on NET when people try to install OS on an Eee PC (no cdrom). Hope it helps http://www.multimolti.de/blog/2008/12/14/install-windows-7-on-asus-eee-pc-900/ And a guidance for the ASUS Eee PC 901 and 1000 series notebooks Quote General Quote from: tonlo on April 21, 2009, 04:44:31 AM My solution: Will not work. |
|
| 3326. |
Solve : flash drive ram? |
|
Answer» Quote from: tonlo on April 21, 2009, 11:43:11 AM My idea. You want to put page file/swap file on a flash drive? That would kill the flash drive quickly. Quote from: DIAS de VERANO on April 21, 2009, 12:02:12 PM You want to put page file/swap file on a flash drive? That would kill the flash drive quickly. That's why let people use my extra blank DVD's for partition transfer.I personally don't suggest steven32collins to do that. I just answer "is there a way" question.http://www.microsoft.com/windows/windows-vista/features/readyboost.aspxQuote from: Geek-9pm on April 21, 2009, 12:54:50 PM http://www.microsoft.com/windows/windows-vista/features/readyboost.aspx This was covered a couple of pages back. Quote Dias de veranoSorry, my bad. Yes, you said that as the first response to the original post. Still - Way would Microsoft allow or document a feature that would cause harm to the Flash device? IMO that is just typical of Microsoft. But it does make we wonder.I think he can make a PART of HD work like RAM. I see that topic starter uses the Windows XP, so he can configure the VIRTUAL MEMORY. P.S. It will work a little bit faster and as you know the data access speed of HD is not such as RAM Cheers.Quote would Microsoft allow or document a feature that would cause harm to the Flash device? No. Some people have the incorrect and mistaken idea that Readyboost works by storing the swap file on the flash drive. This is not so. Readyboost does not exercise a flash drive in the same way that using it as a swap partition would. Flash memory can only take so MANY writes. Even with techniques such as wear levelling, swap file use will destroy a flash drive in a fairly short time. The core idea of ReadyBoost is that a flash drive has a much faster seek time (less than 1 millisecond), allowing it to satisfy requests faster than a hard disk when booting or reading certain system files. (System files, right? That don't change - write once, read many times) By the way, unless you have USB 2.0 and you are using a top end pen drive or memory card ReadyBoost won't make a lot of difference. And even then it won't be anything to write home about. A swap file on the other hand is constantly changing as memory is paged in and out. Furthermore, Windows uses the page file in blocks of 4096 bytes but flash memory usually has logical blocks of 65536 Bytes and whenever a 4K block is written the flash device has to erase and rewrite a whole 64K block. So pretty soon all the memory cells on the flash drive will be worn out. |
|
| 3327. |
Solve : Delete zero size files in a drive eg:D:\ in win xp? |
|
Answer» HelloI use XP SP3 too and ('dir /b /s /a-d') worked fine. I don't know why it didn't work for you. One thing - if you scan a whole drive there may be a long time when NOTHING seems to be happening. I use XP SP3 too and ('dir /b /s /a-d') worked fine. I don't know why it didn't work for you. One thing - if you scan a whole drive there may be a long time when nothing seems to be happening. The above method delete files one by one. Not that its really a big deal, but a suggestion for a more efficient way, since del can delete multiple files passed to it on the command line, is to concat all the FILENAMES into one string, either by batches (or as many as del can TAKE as input) and then pass it to del. Hello |
|
| 3328. |
Solve : deleting multiple files with batch? |
|
Answer» Hey guyz, im trying to delete the copies of my songs in a directory. i got alot of files with the same file name and its annoying trying to delete one by one, eg. yea, thats ok with just 1 file, but im talking over 1000 with over 300 directories. Originally you wanted to save one file in a directory. Quote from: Khasiar on April 23, 2009, 11:07:39 PM Hey guyz, im trying to delete the copies of my songs in a directory. Could you EXPLAIN a little more of what you mean to accomplish as well as, like Dusty said, describing the directory tree that contains these files you want to delete?The following will do binary compare: ------------------------------------ 1. Traverse all the directory and save the listing to a temp file 2. SORT temp file by file size 3. for each files with the same size, do file compare fc.exe/b song1.mp3 song2.mp3 The following will do file name check: ----------------------------------- 1. Traverse all the directory and save the listing to a temp file 2. sort temp file by file name 3. for each files with the same name, delete duplicate(s) which one are you after?ok. same file names in the same directory? possible on windows file system?Quote from: gh0std0g74 on April 24, 2009, 05:48:15 AM ok. same file names in the same directory? possible on windows file system? Is your question rhetorical? That would cause an ERROR if some of the files have exact duplicates in the same directory when you try to use MOVE, or copy.i was actually trying to ask if OP's duplicate files are in different folders or not, because AFAIK(am not a windows expert) , wouldn't the OS give error you there are same file name ( case insensitive ).No idea at this point. First it sounded like 1 file of many in a directory, now it's 1000 files over 300 directories. In either case, it's impossible for two identical files with identical names to exist in the same directory.Sorry to confuse everyone, the main situation is that i have many files that are the same in different directories. eg c:\music\artist\123.mp3 c:\music\favs\123.mp3 c:\music\mymusic\123.mp3 c:\music\hismusic\123.mp3 problem is, ive copied most of them, and when i look in my media library i see doubles, triples and even up to 5 times the same song.... i know what was i thinking lol... but this was my first attempt of trying to arrange my files in a somewhat orderly manner by artist etc... and its a horrible mess... any help would be great... Khasiar if you have Perl and can use it. Uses MD5 to check for file duplicates. Code: [Select]use Digest::MD5; use File::Find; use File::Copy; my %seen; my $destination = "c:/tmp"; sub getmd5 { my $file = $_[0]; open(FH,"<",$file) or die "Cannot open file: $!\n"; binmode(FH); my $md5 = Digest::MD5->new; $md5->addfile(FH); return $md5->hexdigest; close(FH); } sub wanted { if ( -f $_ && /\....$/ ){ my $file = $File::Find::name; my $md5 = getmd5 $file; if ( defined($seen{$md5}) ){ # duplicates print "duplicate $file" . "=>" . $md5 ." \n"; unlink $file or die "Cannot remove $file:$!\n"; }else{ $seen{$md5} = $file; } } } my $dir = "c:/test"; # Traverse desired directory File::Find::find({wanted => \&wanted}, $dir); foreach my $v (values %seen){ print "\$v: $v\n"; move ("$v", "$destination" ) or warn "Cannot move file to destination:$!\n"; } alternatively, if you want to do in batch, you can use fc command, for loop, doing some if else check etc etc.. Ahhh ok. If you're running Windows, might be easier to use something like this: http://www.snapfiles.com/get/dupfilefinder.htmlThanks quaxo im pretty sure this is excatly what i wanted, using it now so ill let you know if it works laters .. cheers Khasiar |
|
| 3329. |
Solve : showing all files in all subdirectories by owner attribute? |
|
Answer» grant, here it is. code becomes longer with the additional feature, i've try my BEST to make it as compact as possible. so at this point, I give up on DECIPHERING your code but I'll run it and trust that it works!there is only one way to make to code more readable, modify it to become longer by using the usual syntax, eg lots of if else if else, set, for, etc. i just notice that for network share, the owner file name is not computername\username, but something like this: Code: [Select]05/30/2008 03:49 AM <DIR> \Everyone FolderA 04/23/1999 07:22 AM 93,890 \Everyone COMMAND.COM 05/11/1998 05:01 AM 33,191 ... HIMEM.SYS 03/07/2009 01:34 AM 85,504 BUILTIN\Administrators sample.txt Quote from: Reno on March 21, 2009, 03:55:36 AM grant, here it is. code becomes longer with the additional feature, i've try my best to make it as compact as possible. Reno - I didn't get a chance to REPLY to this last message. The project's been pushed back farther and farther and I expect to be using this tool in June some time. You've saved me tons of time and I really appreciate it! Thanks! |
|
| 3330. |
Solve : File Management? |
|
Answer» Hi there Hi there Hints: 1) copy/xcopy/MOVE. See copy /?, move /?, xcopy /? for more 2) ren /? , rename /? 3) call /?HelloHelloHello |
|
| 3331. |
Solve : How to - If user clicks EXIT then unmount (popd) network drive? |
|
Answer» I have a batch file that mounts a drive and runs various scripts on a network drive. Once the scripts completes the drive automatically unmounts. If the user clicks the exit button on the dos window I would like to unmount the drive. Do you KNOW how unmount a drive if the user exits the batch operation? Thanks MC |
|
| 3332. |
Solve : how creat ip address ,sub net mask default gatway batch file? |
|
Answer» my office ip address is xxx.xxx.xxx.xxx.xxx |
|
| 3333. |
Solve : Automatic Set IP? |
|
Answer» My BAT script To make the script automatically, i think the first thing i need to know DHCP status of the interface. and then if DHCP is yes ----> run :function2, else run function1. I don't know how to get the DHCP status of an interface, how if machine have 1 interface and more than 2 interface?Now the second thing is function2, it still request user input. Can we it automatic too? My solution is random a number between 1-254 and set to X. And then run ping command if it is request time out --> set X ---> done, Else loop random again. It will have a risk if there are a machine enable firewall. Quote from: tonlo on April 20, 2009, 11:33:28 PM Now the second thing is function2, it still request user input. Can we it automatic too? My solution is random a number between 1-254 and set to X. And then run ping command if it is request time out --> set X ---> done, Else loop random again. It will have a risk if there are a machine enable firewall. You can refer to below code to get an available IP. Let me know if you need further help. Code: [Select]@echo off set IPPart1=192 set IPPart2=168 set IPPart3=10 set IPPart4=# echo Need MINUTES to look for an available IP. for /l %%a in (2,1,254) do ( ping -n 1 -l 1 %IPPart1%.%IPPart2%.%IPPart1%.%%a >nul ) rem Don't care whether an IP is pingable. We just need the arp cache. arp -a>"%temp%\UsedIP.tmp" for /l %%a in (254,-1,2) do ( findstr "%IPPart1%\.%IPPart2%\.%IPPart3%\.%%a" "%temp%\UsedIP.tmp"||set IPPart4=%%a goto :FindIP ) :FindIP set AvaiIP=%IPPart1%.%IPPart2%.%IPPart3%.%IPPart4% if "%IPPart4%" neq "#" ( echo Find an available IP: %AvaiIP% ) else ( echo No IP is available currently. ) pause goto :eof Hi BATCHER, Maybe that is your typing mistake Quote for /l %%a in (2,1,254) do (ping -n 1 -l "missing size" %IPPart1%.%IPPart2%.%IPPart3%.%%a >nul I understand why to ping all the IP in subnet 192.168.10/24. But i take so long, i changed the buffer size to 10byte to test how long does it take. Over 2min just for get ARP table. I can't spend 2min to automatic set the IP address because i can set IP in window graphic mode in ~30s. Any better solutions?if you allways want same 'x' then use this : Code: [Select]:function2 set x=24 echo IP : 192.168.10.%x% Can't because i will share my script with other people in LAN. It will occur conflict IP. How about if it change subnet to 16, and random the 3rd, 4th Octet. More random time, more less conflict happen Code: [Select]@echo off setlocal enabledelayedexpansion set IP=192.168.10 for /L %%P in (10,1,30) do ( ping -n 1 -w 10 %IP%.%%P >nul if !errorlevel! equ 1 echo.%IP%.%%P is free... if !errorlevel! equ 0 echo.%IP%.%%P isn't free... ) pause you can use that so all people in lan can get first free IP it took me 11 sec to check 20 ip'sHi tonlo, I've fixed that typo. Thanks for your reminder. |
|
| 3334. |
Solve : DOS filerename error? |
|
Answer» I am getting the following error message: |
|
| 3335. |
Solve : Sync Environments? |
|
Answer» Hi there |
|
| 3336. |
Solve : forgot how to copy from drive a: diskette to drive c: hardrive? |
|
Answer» How do I copy INFO from diskette a: to C: ? FORGOT the FORMULA. O.J.type COPY /? at the PROMPT |
|
| 3337. |
Solve : Explain THis Huge Dupe plsssssssssss.....? |
|
Answer» @echo off |
|
| 3338. |
Solve : Insert lines at top of file? |
|
Answer» I'm new to the BATCH writing world so bear with me. I want the batch to open up a delimited text file and insert 6 pre-defined lines from another text file(the insert file will only contain the six lines to be used as a header). at Line 1 of the file. I've tried using the "type" command, but it is overwriting the existing text. |
|
| 3339. |
Solve : 7-zip extraction style Problems? |
|
Answer» hey every1 can u give me the codei don't think he will. Why don't you PUT in some effort. He has already told you want to do.Well I'm not quite as tired as Salmon Trout so here's the code. Quote from: great_compressor_pain on November 17, 2009, 01:14:50 AM thanks SalmonYou have to respect the fact that we don't like doing ALL the work around here. ST gave you the source for all the information you need to run 7-zip or whatever from the command line. If you don't want to look for yourself and do a bit of work, then you shouldn't try and do what you are trying to do. Thanks everyone Al dos Who Hate me I ve Got the Code Special Thanks To Salmon Trout... it waz in Front Of me and i couldnt Understand its [-y] |
|
| 3340. |
Solve : passing variables? |
|
Answer» I'm trying to write a batch file that gets the IP address of a site using NSLOOKUP, when an IP is found it opens and launches INTERNET explorer using that IP address. Is this possible? |
|
| 3341. |
Solve : Bat file and mouse cursor? |
|
Answer» Hey all. Hey all.I don't think it's possible...Well... How does Windows do it then? Sure, there's a GUI, but it must be saving the information somewhere... I mean... when you copy and paste a file somewhere, it's essentially just the, "xcopy" command done in a GUI layout... Ahhh!! More comments/help?Quote from: Supervisor on April 20, 2009, 03:17:52 PM Well... How does Windows do it then? Well there are .theme files...but I think they might be a bit too complex for batch to handle...anyway, batch makes itself usefull for doing repetative tasks, like MOVING backups, can't you just change your cursor manually?As I said before, I'm sending out the cursor to a couple of people (who loved it by the way, so please try it :-D) who aren't that great with computers... If I could just change it with a BAT file, it would be much easier.Quote from: Supervisor on April 20, 2009, 03:37:07 PM If I could just change it with a BAT file, it would be much easier. I'm sure it would, but it ain't gonna happen. Once again, we ask: why do people think that batch files can do absolutely anything?Quote from: Dias DE verano on April 20, 2009, 03:46:31 PM I'm sure it would, but it ain't gonna happen. Once again, we ask: why do people think that batch files can do absolutely anything?Do it in one EXREMELY complicated step, or about 3 easy steps.Quote from: Helpmeh on April 20, 2009, 03:48:00 PM Do it in one EXREMELY complicated step, or about 3 easy steps. Go on then, maestro, get your violin out and give us a tune...main.cpl is the control panel for mouse. you could google the command LINE argument needed to pass to main.cpl, as i don't have the list.Quote from: Dias de verano on April 20, 2009, 03:46:31 PM Once again, we ask: why do people think that batch files can do absolutely anything? Heck I have batch doing every thing from washing the dishes to taking the dog for a walk. Just don't get me to try and get it to do anything computer wise. |
|
| 3342. |
Solve : I need help with a bat file, to call an exe over a network? |
|
Answer» Hi He wants it to run on start up, he can run it from there by Scheduling it, but when the server is down then he probably wants it outside of the server. That doesn't make sense to me though as he is sending the info directly to a server so if it's down, what's the point?it might be that when computer boot up and batch file is called, it's not YET FINISH connecting to network: so try put some delay into it: Code: [Select]::checkserver.bat @echo off >nul ping localhost >nul ping 192.168.1.1 || (%0) && call yourbatch.batQuote from: BumFacer on April 23, 2009, 05:51:49 AM Can you not just run the .exe from the server location e.g.: Hi Thanks for that, i had tried that, but i must have had the wrong path, i tried it again with this path \\servername\SYSVOL\Marine.ie\scripts\LSclient.exe miinvser And its working fine now. the .exe file is one which works with lansweeper software, which brings back information on the PC / software etc that the user logs on to, so i needed it to run at login/startup. its sorted now, thanks again. Damien glad you sorted it out. you are good poster, nowadays there are rarely a poster with the polite attitude to report back. if you have any more trouble, don't hesitate to ask. |
|
| 3343. |
Solve : How do I access cmd DOS from Vista?? |
Answer» QUOTE from: Broni on April 22, 2009, 07:25:39 PMIt all depends how COMPUTER savvy you're, and how comfortable you feel working around the computer.True.basically- if your not savvy enough to disable the OPTIONS- you probably NEED them, anyway... |
|
| 3344. |
Solve : Delete first line of file? |
|
Answer» I need to delete ONLY the first line of each FILE. The first line contains the text |
|
| 3345. |
Solve : scripts? |
|
Answer» I just WANT to write a script that will backup my documents, pictures, music, emails and desktop of my desktop to the server I just want to click on this script and back all of this information to the map DRIVE on the server any one can help me here to write this script.Hint: |
|
| 3346. |
Solve : How to disable close "X" button in DOS? |
|
Answer» it works great. GetConsoleWindow() nice |
|
| 3347. |
Solve : removal on start up? |
|
Answer» when i turn on my COMPUTER a screen POPS up with regclean 32 i exe how do i REMOVE itDouble Post |
|
| 3348. |
Solve : Run the batch file if any .txt files exists?? |
|
Answer» I have some .txt FILES in C:\temp. |
|
| 3349. |
Solve : Appending Transport Name and Mac Address to txt file? |
|
Answer» Im currently working on a simple batch file for my computer class, and am STUCK on one part. the instructions are as follows: |
|
| 3350. |
Solve : Batch file to check when it was lat run?? |
|
Answer» May I but in ? OK, I will anyway. MS-DOS System Date Cannot Have a Year Past 2099It apples to Microsoft MS-DOS 6.22 Standard Edition, so if you really use DOS and not the XP command prompt, you can have a problem. Maybe. I don't know. Quote from: devcom on April 27, 2009, 10:45:57 AM try this: if your date looks like yyyy/mm/dd then change every delims=- to delims=/you could do all of this in vbscript Code: [Select]'lastrun.vbs - check for vbs lastrun and rename a folder if less than 7d f=".\testfolder" with createobject("scripting.filesystemobject") if not .folderexists(f) then wsh.echo f, "not exist":wsh.quit 1 lastrun=now if .fileexists(".\dummy.txt") then lastrun=.getfile(".\dummy.txt").datelastmodified wsh.echo "Last run:",lastrun if datediff("d",now,lastrun)<7 then d=.getbasename(f) & "_" & right(year(date)*10000+month(date)*100+day(date),6) wsh.echo "Less than 7 days, rename to", d .getfolder(f).name = d end if set dummy=.opentextfile(".\dummy.txt",2,true) dummy.writeline now dummy.close end withto run, type at command prompt "lastrun.vbs" use cscript engine: cscript//nologo lastrun.vbs use wscript engine: wscript//nologo lastrun.vbs or if you insist on batch code, i've the pure batch code which is twice the size of vbs code. or you could have the best of both world with the above code by devcomThanks everyone for all your help. I'm gonna go away ant try these out. no doubt, i'll be back if i get confused Hi - back again I am almost there, however there is ONE small problem. The script successfully renames the test folder, however when i run it again it should do the comparison to see when it was last run. It was run less than 7 days ago the 'rename will not be performed' message should display. The script for some reason is not doing this. When i run it for the second time I get the 'duplicate file name exists or location cannot be found' error instead. I think it is because of the "if not" statement that compares the 2 dates to see whether 7 days have elapsed. The 2 variables are in different formats and therefore the statement fall over. i.e. Date = 28/04/09 Date7 - 05052009 Am I correct in this? and how to I get the date.txt in the same format as the date7 variable? thanks Code: [Select] @echo off for /f "tokens=1-3 delims=/ " %%A in ('cscript //nologo evaluate.vbs date') do set yymmdd=%%C%%B%%A set org=test pause if not exist date.txt cscript //nologo evaluate.vbs date >date.txt set /p date=<date.txt for /f "tokens=1-3 delims=/ " %%A in ('cscript //nologo evaluate.vbs date+7') do set date7=%%A%%B%%C if not %date:+=% GEQ %date7:+=% ( echo Rename will not be performed. pause >nul exit ) pause ren %org% %org%_%yymmdd% cscript //nologo evaluate.vbs date >date.txt echo. DONE! pause forgot to told this to you you also NEED to change this: Code: [Select]if not %date:+=% GEQ %date7:+=% ( to Code: [Select]if not %date:/=% GEQ %date7:/=% ( so it can remove it and i don't know why Date & Date7 are in different format... they should be the same as it uses the same command Hi, I'm almost there - so the batch file runs and successfully renames the test folder to test_yyyymmdd If I create another test folder and run the batch file again - it should check if the batch file has been run in the last 7 days and then decide wether to run or not. So in the case of me creating the second test folder, the batch file should not run as i have previosuly run it on the same day. I have tried this and it is not working I get the following error - "A duplicate file name exists, or the file cannot be found" What am I doing WRONG? Code: [Select]@echo off for /f "tokens=1-3 delims=/" %%A in ('cscript //nologo evaluate.vbs date') do set yymmdd=%%C%%B%%A set org=test for /f "tokens=1-3 delims=/" %%A in ('cscript //nologo evaluate.vbs date') do set current=%%A%%B%%C if not exist date.txt echo.%current% >date.txt set /p date=<date.txt for /f "tokens=1-3 delims=/" %%A in ('cscript //nologo evaluate.vbs date+7') do set date7=%%A%%B%%C if not %date:/=% GEQ %date7:/=% ( echo Rename will not be performed. pause >nul exit ) ren %org% %org%_%yymmdd% echo.%current% >date.txt echo. DONE! pause final code i think edit: or no... edit: if i understand you good add this in front of file: Code: [Select]for /f "tokens=*" %%a in ('dir /b ^|findstr "%org%"') do ( if not "%%a" equ "%org%"( echo Error: %%a pause >nul exit ) ) |
|