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.
| 251. |
Solve : close windows on error with batch file? |
|
Answer» Hi Are you going to let us see the batch file, or not?My cat is called Ginger. Corruption once again. Anyway, Ginger, you could try something in the likes of CODE: [Select]IF pingDoesntSucceed DO exit iexplorer (I don't know, I'm just giving some tips here). Quote from: Big on September 04, 2010, 08:47:23 PM Corruption once again. That would be the general idea. (will probably use tskill/taskkill iexplore or something to that effect). Ping seems to give an errorlevel of 1 if the host is not found. (although for some reason it is able to resolve www.sdkjfksdhfkjshdjf.com, and thinks it exists (?)) It would probably take additional checking with things like ipconfig to be sure that there isn't a internet connection at all (since invalid hosts still seem to resolve, but that might just be my DNS). Another problem is that most task kill programs kill all open tasks of that program, so killing the single process of internet explorer that was started isn't quite as simple as it seems at first glance- you wouldn't want the person running the batch to be using internet explorer (or even worse, a program using IE as an out of process COM component) and suddenly kill all instances of IE. Only other way is to provide the window title, but IE changes it's window title in such a way that it's somewhat difficult to predict. Ideal solution might require a third-party "APPLICATION starter" that allows you to get the Pid of the program, which can be used by tskill to kill a specific instance.I think, rather than ponder how to close the right instance of Internet Explorer, I would rather avoid opening it at all, and use something like wget or curl, or a vbscript to find out if the network connection, website and desired file are all available, if so to get the file, if not to take appropriate action. Quote from: Salmon Trout on September 05, 2010, 12:31:40 AM I think, rather than ponder how to close the right instance of Internet Explorer, I would rather avoid opening it at all, and use something like wget or curl, or a vbscript to find out if the network connection, website and desired file are all available, if so to get the file, if not to take appropriate action. For some reason that never even occurred to me, even though at the time I replied I was working on a CLASS that does something very similar in C#. Code: [Select]F:\>ping www.slkqjdfmlkjsdf.com Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name a nd try again. Quote from: Big on September 05, 2010, 09:07:40 AM Code: [Select]F:\>ping www.slkqjdfmlkjsdf.com Code: [Select]C:\Users\BC_Programming>ping www.slkqjdfmlkjsdf.com Pinging www.slkqjdfmlkjsdf.com [67.215.65.132] with 32 bytes of data: Reply from 67.215.65.132: bytes=32 time=87ms TTL=55 Reply from 67.215.65.132: bytes=32 time=86ms TTL=55 Reply from 67.215.65.132: bytes=32 time=85ms TTL=55 Reply from 67.215.65.132: bytes=32 time=100ms TTL=55 Ping statistics for 67.215.65.132: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 85ms, Maximum = 100ms, Average = 89ms Quote since invalid hosts still seem to resolve, but that might just be my DNS I'm pretty sure it is. Let's have a try... Code: [Select]C:\>ping www.slkqjdfmlkjsdf.com Pinging www.slkqjdfmlkjsdf.com [81.200.64.50] with 32 bytes of data: Reply from 81.200.64.50: bytes=32 time=29ms TTL=56 Reply from 81.200.64.50: bytes=32 time=36ms TTL=56 Reply from 81.200.64.50: bytes=32 time=28ms TTL=56 Reply from 81.200.64.50: bytes=32 time=32ms TTL=56 Ping statistics for 81.200.64.50: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 28ms, Maximum = 36ms, Average = 31ms Hmmm... try a tracert... Code: [Select]C:\>tracert 81.200.64.50 Tracing route to advancedsearch.virginmedia.com [81.200.64.50] over a maximum of 30 hops: 1 7 ms 22 ms 37 ms 10.25.252.1 2 8 ms 37 ms 16 ms aztw-geam-1b-ge210.network.virginmedia.net [80.1.243.133] 3 48 ms 29 ms 23 ms aztw-core-1b-ae0-0.network.virginmedia.net [80.1.241.13] 4 8 ms 9 ms 37 ms brhm-bb-1b-as1-0.network.virginmedia.net [213.105.175.161 5 52 ms 79 ms 69 ms manc-bb-1a-as6-0.network.virginmedia.net [62.253.185.134] 6 14 ms 39 ms 14 ms manc-bb-1b-ae5-0.network.virginmedia.net [213.105.174.186 7 34 ms 25 ms 36 ms te-4-3.ar3.CDG2.gblx.net [204.246.200.177] 8 29 ms 28 ms 29 ms 64.214.140.138 9 30 ms 41 ms 37 ms advancedsearch.virginmedia.com [81.200.64.50] Trace complete. Quote from: Tracert output advancedsearch.virginmedia.com Aha! Code: [Select]C:\>ping www.slkqjdfmlkjsdf.com Ping request could not find host www.slkqjdfmlkjsdf.com. Please check the name and try again. That's better. Quote from: BC_Programmer on September 05, 2010, 09:12:30 AM
Sure looks that way Code: [Select]C:\>tracert 67.215.65.132 Tracing route to hit-nxdomain.opendns.com [67.215.65.132] over a maximum of 30 hops: 1 64 ms 14 ms 8 ms 10.25.252.1 2 45 ms 19 ms 233 ms aztw-geam-1a-ge147.network.virginmedia.net [80.1.243.1] 3 33 ms 10 ms 11 ms aztw-core-1a-ae0-0.network.virginmedia.net [80.1.241.9] 4 50 ms 31 ms 34 ms winn-bb-1a-as0-0.network.virginmedia.net [213.105.175.157] 5 12 ms 44 ms 12 ms brnt-bb-1b-as5-0.network.virginmedia.net [213.105.172.234] 6 59 ms 16 ms 16 ms 195.50.91.129 7 47 ms 17 ms 35 ms ae-32-52.ebr2.London2.Level3.net [4.68.117.62] 8 17 ms 70 ms 45 ms ae-3-3.ebr1.London1.Level3.net [4.69.141.189] 9 28 ms 15 ms 50 ms ae-100-100.ebr2.London1.Level3.net [4.69.141.166] 10 41 ms 31 ms 23 ms ae-48-48.ebr2.Amsterdam1.Level3.net [4.69.143.81] 11 68 ms 27 ms 24 ms ae-2-52.edge4.Amsterdam1.Level3.net [4.69.139.170] 12 35 ms 46 ms 65 ms SPLICE-COMM.edge4.Amsterdam1.Level3.net [212.72.40.98] 13 23 ms 54 ms 57 ms hit-nxdomain.opendns.com [67.215.65.132] Trace complete. |
|
| 252. |
Solve : Command vs Batch file? |
|
Answer» I am using the MOVE command, but running in to a problem. If I put the command in to a Command WINDOW it works fine, but from a batch file I get errors. Why? I am running on a Windows 7(64 bit). |
|
| 253. |
Solve : Reproduce unicode from text file?? |
|
Answer» I'm writing a script which I want to support reading unicode paths from a text file. I want all the unicode to be reproduced the same as pasting the characters into DOS where it appears as a square-like character. (DOS has no problem dealing with unicode characters, they just can't be displayed and this is fine.) I just realized that what I posted might not work. Do you just want all the unicode characters removed from the string or do you want to replace them with a space or a box or what? Thanks for your help Linux but you're still misunderstanding what's required. If you have Windows, open a command prompt window and paste this: Code: [Select]for /f "usebackq delims=" %x in ('"C:\Folder き"') do set myvar=%x This sets myvar to "C:\Folder き". The き character is displayed as a square, but it is still read as き. Do this to save a text file unicode.txt as UTF-16LE (Unicode) containing "C:\Folder き": Code: [Select]%ComSpec% /u /c echo:"C:\Folder き">unicode.txt Then try this: Code: [Select]for /f "delims=" %x in ('type unicode.txt') do set myvar=%x Does nothing because type fails. Then try: Code: [Select]type unicode.txt You will see that this does not output "C:\Folder き", but instead: Code: [Select] C : \ F o l d e r M0" So I need something that will output "C:\Folder き". ghostdog74: I'll try your code as well. Thanks!ghostdog74, I installed Python 3.1.2 and saved your script as read.py. My UTF-16LE file uni.txt contains: "C:\Folder き" Both files are inside the current directory. This is my MS-DOS command prompt: What am I doing wrong? Quote from: orange_batch on September 08, 2010, 11:15:00 PM What am I doing wrong?if you are using Python 3.1 ++, the print statement is now a function, so add brackets. Code: [Select]import codecs import sys inputfile=sys.argv[1] f = codecs.open( inputfile, "r", "utf-16" ) for line in f: print(line) And Python is particular about indentation, so indent properly.I'm not 100% sure how much better it would be as an alternative but following your example, I used more < unicode.txt and I got this: Code: [Select]D:\>more < unicode.txt "C:\Folder ?" So I thought- maybe changing the codepage and THEN using this more to do it will work? Code: [Select]D:\>chcp 65001 Active code page: 65001 D:\>more < unicode.txt Not enough memory. That was certainly an unexpected result. I wasn't able to get anything useful out of it either. ( tried copy unicode.txt con as well, which gave the same result as the type command). I found the fact that more wasn't displaying it spaced out and had a question mark rather then the ASCII-i-fied unicode promising, but redirecting that to a text file, even if I used the /u switch to start cmd still resulted in ASCII, with the double-byte character being converted to a question mark. Personally, I'd go with GhostDog's solution. Quote from: orange_batch on September 08, 2010, 11:15:00 PM ghostdog74, I installed Python 3.1.2 and saved your script as read.py.I think the codecs package/import is deprecated, or at least the codecs.open routine is, in python 3.1 and later. works in activestate perl 2.6.4... or, to be more precise, it runs. (without a syntax error, not sure why you are getting that) I do get this though: Code: [Select]D:\>python D:\test.py unicode.txt Traceback (most recent call last): File "D:\test.py", line 5, in <module> for line in f: File "C:\Python\lib\codecs.py", line 679, in next return self.reader.next() File "C:\Python\lib\codecs.py", line 610, in next line = self.readline() File "C:\Python\lib\codecs.py", line 525, in readline data = self.read(readsize, firstline=True) File "C:\Python\lib\codecs.py", line 472, in read newchars, decodedbytes = self.decode(data, self.errors) File "C:\Python\lib\encodings\utf_16.py", line 90, in decode raise UnicodeError,"UTF-16 stream does not start with BOM" UnicodeError: UTF-16 stream does not start with BOM for some reason the command prompt doesn't redirect it's unicode output with a Byte Order Marker. I did a little looking to see if there was a way to specify to the open method to pretend there isn't a BOM and go with either LE or BE ordering, but my search was fruitless. It appeared to work for ghostdog, so I assume we are both doing something incorrect- your version is too new (no idea wether this is really the case) and probably changed something, whereas I... well, I'm not sure what I did wrong. perhaps I made the unicode file incorrectly. Updated. Same here BC. BC, Orange, first of all, the cmd.exe shell does not support utf-16, so its no use using it to run your script (although Python does process it normally at the back end). Secondly, I am using Python 2.6.x. so i am not sure about Python 3.1.X but, here's another method Code: [Select]data = open("c:\\test\\file1", 'rb').read() decoded = data.decode('utf-16') print decoded try the above using the Python Windows editor (comes with distribution) or some other platform that can display unicode.. I only know the tip of the iceberg of unicode so for more information, check with the docs 1) Unicode how to 2) codecs module 3) search at stackoverflowWell, the script itself is not unicode (DOS fails spectacularly with that), but it deals with path names which might contain unicode. Microsoft knows some dirty secret about this unicode business. Still not working ghostdog. But I'm not disheartened, because jeb on DosTips.com made me realize a fair enough workaround: First of all, I'm only dealing with folder names, but this can be applied to files as well. Forget the whole cmd /u thing and it outputs the ? in place of unicode as usual. ? matches any single character in a path, including unicode. Retrieve the unicode in a folder name: for /d %%x in ("C:\Folder ?") set folder="%%x" (or retrieve the unicode in a file name:) for %%x in ("C:\file ?") set file="%%x" There are two problems however: 1. "C:\Folder ?" will match both "C:\Folder き" and "C:\Folder こ", etc. 2. for /r "C:\Folder ?"... does not work. Other things might not work either, without retrieving the unicode. Solution: pushd "C:\Folder ?" then for /r with no "path" (processes current directory) then popd. For the first problem, we can detect if it returns more than one result or not. If it does, have the user choose between which folders during run-time. This would have to verify each folder containing ? from the root folder to the most descendant folder. Parent folders can be filtered further by their descendants, unless the descendant folders exist in both parents, or something to that effect. I'm going to figure it out and work on a script for this. It's the best that can be done. If anyone who comes across this can manage a solution to the original problem, it would still be desired. |
|
| 254. |
Solve : How to get back to the command line?? |
|
Answer» Assume I have one EXCEL file locates at H:\My Documents\Docs\X.xls. I start it by command "CALL H:\My Documents\Docs\X.xls". After X.xls is started, the command line can not accept NEW input until the X.xls file closed. Is there any SOLUTION to get back to command line and make the new input workable and meanwhile no need to close X.xls? Thanks!H:\My Documents\Docs\X.xls just thatDont USE call, use start |
|
| 255. |
Solve : Batch File- Delete Files (Folder Name is a Variable)? |
|
Answer» So to make this as simple as possible... So to make this as simple as possible... Simple is good, but the post is a little short on specifics. It would have been nice to know the registry key. You can use the reg query utility to extract the directory name from the registry and then use the del command with a wildcard. Something like his may help: Code: [Select]echo off for /f "skip=2 tokens=3" %%i in ('reg query HKLM\system\currentcontrolset\services\tcpip\parameters /v databasepath') do echo del %%i\* The registry key is the path found in the left pane of the regedit program. The /v switch value is the name field found in the right pane of the regedit program. The value returned by the for statement is the data field in the right pane of the regedit program. The code snippet contains an echo instruction to prevent any deletions until you are satisfied the returned directory is valid. Remove when you are ready. The snippet can be modified to delete the files (attachments) individually in case you need to keep some based on name or date or whatever. Good luck. |
|
| 256. |
Solve : datestamp help? |
|
Answer» hi all - I need a batch file to search in a directory. If all the files have the current date stamp then execute command1 if files are not current then execute command2. This can be done via Perl or a number of other languages which have abilities to compare strings, but I cant see doing this in raw batch. It is a commonplace everyday task for batch. It can easily be done... using FOR and the ~t variable modifier you can get the "date" (created or last modified?) of each file, and it is trivially easy to get today's date. However we do not know the OP's local date format or the format returned on his system by ~t The output of this script will TELL us those things. Code: [Select]echo off echo local date format [%date%] echo.>temp$$$ for /f %%A in ("temp$$$") do echo file date format [%%~tA] del temp$$$ pause For example, I get this Code: [Select]local date format [22/09/2010] file date format [22/09/2010 07:46 AM] But I am worried about this in the question Quote I need a batch file to search in a directory. If all the files have the current date stamp then execute command1 if files are not current then execute command2. All the files? What if 99 do and 1 does not? Likewise for the converse situation. these files will ALWAYS have the same date. I guess we can look in one particular file to check for the date. thanks Quote from: x3g on September 22, 2010, 07:58:01 AM these files will always have the same date. I guess we can look in one particular file to check for the date. So did you run my script? your script works good but it is missing the logic I need. Quote from: x3g on September 22, 2010, 09:44:19 AM your script works good but it is missing the logic I need. I asked you to run the script so I could see your local date format. Then I can make a script for you with the logic that you need. ah here it is local date format [Wed 09/22/2010] file date format [09/22/2010 11:14 AM] thank you. Code: [Select]echo off setlocal enabledelayedexpansion REM Of course you UNDERSTAND you need to edit this set foldername="S:\Test\Batch\After 03-07-2010\test-file-date" set pdate=%date% set today=%pdate:~4,10% REM get file date of latest file in folder for /f "delims=" %%A in ( ' dir /b /a-d /od %foldername% ' ) do ( set fdate=%%~tA set fdate=!fdate:~0,10! ) if "%fdate%"=="%today%" ( goto yes ) else ( goto no ) :yes echo YES!!! rem Code to execute if file date is today goto next :no rem Code to execute if file date is not today echo NO!!! :next REM whatever happens next... pause this looks very promising. I'll let you know my feedback once I've tested. Thank you. the YES condition works great but the NO logic only works for files that are older than 1 day. If the latest files are from yesterday it will still run the YES logic. Quote from: x3g on September 22, 2010, 01:13:29 PM the YES condition works great but the NO logic only works for files that are older than 1 day. If the latest files are from yesterday it will still run the YES logic. are you quite sure about this? Because the test would be if "09/21/2010"=="09/22/2010" which should fail and therefore the else CLAUSE gets triggered. Could you insert these diagnostic lines shown in red? echo off setlocal enabledelayedexpansion REM Of course you understand you need to edit this set foldername="S:\Test\Batch\After 03-07-2010\test-file-date" set pdate=%date% set today=%pdate:~4,10% REM get file date of latest file in folder for /f "delims=" %%A in ( ' dir /b /a-d /od %foldername% ' ) do ( set fdate=%%~tA set fdate=!fdate:~0,10! ) echo today is %today% echo fdate is %fdate% echo comparing [%fdate%] with [%today%] if "%fdate%"=="%today%" ( goto yes ) else ( goto no ) :yes echo YES!!! rem Code to execute if file date is today goto next :no rem Code to execute if file date is not today echo NO!!! :next REM whatever happens next... pause even though the files are dated 9/21/2010 fdate still shows 9/22 today is 09/22/2010 fdate is 09/22/2010 comparing [09/22/2010] with [09/22/2010] YES Press any key to continue . . . are you quite sure there is no file dated 09/22/2010 in that folder, including hidden files? I replaced the 9/21 files with some 9/14 & 9/20 files and get this today is 09/22/2010 fdate is ~0,10 comparing [~0,10] with [09/22/2010] NO Press any key to continue . . . |
|
| 257. |
Solve : Replacing characters in a large amount of folders? |
|
Answer» Hi, what's all that weird euro language stuff? I 'm sorry, I forgot to paste only the relevant part, edited the code now "Er zijn 1 map(pen) verplaatst." means 1 folder has been moved.An alternative, maybe: if you want to take folder names containing # and replace that character with _ why bother using move? Just get the folder name into a string variable, use the replace function of the SET command, and rename the folder with the new string. E.g Code: [Select]echo off setlocal enabledelayedexpansion for /f "delims=" %%A in ('dir /b /ad *#*') do ( set oldname=%%A set newname=!oldname:#=_! echo renaming "!oldname!" to "!newname!" REN "!oldname!" "!newname!" ) To do all subdirectories change dir /b /ad to dir /s /b /ad Before... Code: [Select]C:\test>dir Volume in drive S is USBHD Volume Serial Number is 2C51-AA7F Directory of C:\Test 15/09/2010 08:45 PM <DIR> . 15/09/2010 08:45 PM <DIR> .. 15/09/2010 08:44 PM <DIR> folder#1 15/09/2010 08:44 PM <DIR> folder#2 15/09/2010 08:44 PM <DIR> folder#3 15/09/2010 08:44 PM <DIR> folder#4 15/09/2010 08:45 PM <DIR> folder#4#5#6#####7 15/09/2010 08:44 PM 215 test1.bat 1 File(s) 217 bytes 7 Dir(s) 188,506,218,496 bytes free Code: [Select]c:\Test\>test1.bat renaming "folder#1" to "folder_1" renaming "folder#2" to "folder_2" renaming "folder#3" to "folder_3" renaming "folder#4" to "folder_4" renaming "folder#4#5#6#####7" to "folder_4_5_6_____7" After... Code: [Select]C:\Test>dir Volume in drive S is USBHD Volume Serial Number is 2C51-AA7F Directory of C:\Test 15/09/2010 08:48 PM <DIR> . 15/09/2010 08:48 PM <DIR> .. 15/09/2010 08:44 PM <DIR> folder_1 15/09/2010 08:44 PM <DIR> folder_2 15/09/2010 08:44 PM <DIR> folder_3 15/09/2010 08:44 PM <DIR> folder_4 15/09/2010 08:45 PM <DIR> folder_4_5_6_____7 15/09/2010 08:48 PM 217 test1.bat 1 File(s) 217 bytes 7 Dir(s) 188,506,218,496 bytes free Indeed, this also works, but the effect is in this case exactly the sale with move as rename here? I'm not sure in win7 but I thought rename didn't work for folder in XP? Quote from: Jupke on September 15, 2010, 02:18:59 PM Indeed, this also works, but the effect is in this case exactly the sale with move as rename here? Yes, however move has a potential ambiguity that ren does not, viz: move folder1 folder2 (if folder2 does not exist!) is equivalent to ren folder1 folder2; BUT if folder2 does exist, folder1 can be moved to be a subfolder of folder2, unless its attributes forbid this . However, ren only renames, never MOVES. Quote I'm not sure in win7 but I thought rename didn't work for folder in XP? 1. Where did you get that idea? 2. Could you not have done an experiment? 3. It works for all Windows, as far as I know, as long as you have the right permissions and the folder attributes allow it. Code: [Select]G:\test>ver Microsoft Windows XP [Version 5.1.2600] G:\test>md testdir G:\test>dir Volume in drive G is DATA1 Volume Serial Number is 9476-662D Directory of G:\test 15/09/2010 22:42 <DIR> .. 15/09/2010 22:42 <DIR> testdir 15/09/2010 22:42 <DIR> . 0 File(s) 0 bytes 3 Dir(s) 16,695,369,728 bytes free G:\test>ren testdir cakes-and-coffee G:\test>dir Volume in drive G is DATA1 Volume Serial Number is 9476-662D Directory of G:\test 15/09/2010 22:42 <DIR> .. 15/09/2010 22:42 <DIR> cakes-and-coffee 15/09/2010 22:42 <DIR> . 0 File(s) 0 bytes 3 Dir(s) 16,695,369,728 bytes free G:\test> |
|
| 258. |
Solve : DOS opens Internet Explorer and...? |
|
Answer» I'm trying to figure out how to use DOS CODING to open up Internet Explorer and make it go to a specific site. I know to make it go to IE, I NEED something lie: |
|
| 259. |
Solve : Rename multiple files whose names are contained in an XML file.? |
|
Answer» Hi Guys, Thanks ghostdog! then add the string ".m4a" Code: [Select]os.rename(k,v+".m4a") Its not that difficult. Now, go read up Python docs. |
|
| 260. |
Solve : How to keep FTP connection alive in command line?? |
|
Answer» HI Friends, As you know, in default, FTP connection time out is 120 seconds. It is very boring to re-connect frequently. So is there any way to make ftp connection alive for specified long time or for ever until close it explicitly? I often encountered the following boring message: Connection CLOSED by REMOTE host. Hope you can help me out of this TROUBLE!! Thanks!!possibilities, FTP server configured to close connection after certain time of idling, OR a firewall in between can close the connection. |
|
| 261. |
Solve : shortcut keys for copy and paste in command line? |
|
Answer» Hi Friends, |
|
| 262. |
Solve : "For" and "If" command doubt? |
|
Answer» Hi, I just ran your script twice, and the first time, it renamed "0D0A inside.jpg" to "Front Cover Inside.jpg", and added this line to log.txt My problem is when "Front Cover Inside.jpg" coexists with some file like "0D0A inside.jpg". What I want to be logged is: Code: [Select]"Similar file to "S:\Test\Batch\After 03-07-2010\for-if\0D0A inside.jpg" already exists" which in this case is "Front Cover Inside.jpg"). Then, after reading the log, I will manually check which file is "0D0A inside.jpg" and if it's quality is better than "Front Cover Inside.jpg" it will delete this one. I need this because I have thousands of album art files I don't want to check then one by one... TIAFinally I think I've solved my problem. My final batch looks like this: Quote echo off The trick is using errorlevel. When trying to rename the file, if there's already a file with the same name, MS-DOS will return a error message. I've just use this to sove my problem. I've tried different scenarios and it worked the way I want it. So, I'm proud of myself, considering how newbie I'm in MS-DOS command line... Quote from: vitorb on September 11, 2010, 07:40:29 AM Finally I think I've solved my problem. My final batch looks like this: This is going to start driving me completely INSANE. Quote from: BC_Programmer on September 11, 2010, 08:33:52 AM
Sorry... You're completely right! I know that MS-DOS it's a operating system and what I'm using is just a command line interpreter. Ten YEARS ago I USED MS-DOS for a few months, but I never developed any SKILLS on it's usage...And the tweaking goes on... My previous batch had one problem. This code: Code: [Select]for /R %%x in (*inside.jpg) do if not exist "Front Cover Inside.jpg"doesn't seems to work correctly because after the batch finish I saw that every "Front Cover Inside.jpg" files in various directories had been renamed again to it's current name. Code: [Select]ren "%%x" "Front Cover Inside.jpg"Whenever %x is "Front Cover Inside.jpg" it will be: Code: [Select]ren "Front Cover Inside.jpg" "Front Cover Inside.jpg" which is useless... So I've change it this way: Code: [Select]for /R %%x in (*inside.jpg) do if "%%~nxx"=="Front Cover Inside.jpg" ( echo "Front Cover Inside.jpg" already exists ) else ( ren "%%x" "Front Cover Inside.jpg" if errorlevel 1 ( echo Similar file to "%%x" already exists >> Log.txt ) else ( echo "%%x" renomed to "Front Cover Inside.jpg" >> Log.txt ) ) |
|
| 263. |
Solve : sorting folders according to content file extension!? |
|
Answer» Hello .. guys.. can some one tell me if this is possible in a msdos batch file ..yes, its possible. My solution is not batch, so if you can install Python, here's a script you can use Code: [Select]import os import shutil root="C:\\" dirsortedpath=os.path.join(root,"test","sorted") # put sorted path here dirunsortedpath=os.path.join(root,"test","unsorted") # unsorted path os.chdir(dirsortedpath) dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ] for r,d,f in os.walk(dirunsortedpath): for files in f: ext=files[-3:].lower() #get the extension if ext in dirsorted: try: shutil.move(r, os.path.join(dirsortedpath,ext)) except Exception,e: print e else: print "moved .." save as myscript.py on the command line Code: [Select]c:\test> python myscript.py If not, you can wait for your batch solution.that would be no problem. thanx !!!! gone chek it out later this evening thanx... it seems that it moves only the file not the folder so i get root\sorted\te1\xxxxxx.te1 not root\sorted\te1\folder 3\xxxxx.te1 do i have to change more than only the sorted path and unsorted path. thanx.. alot for this piece of code... i use cygwin to do some linux like stuf and it has python installed on default. Quote from: mazhive on September 09, 2010, 05:22:41 AM it seems that it moves only the file not the folder you can always debug your script by using print . First comment out shutil.move line , then just insert a print statement Code: [Select]print "Moving " r , " to ", os.path.join(dirsortedpath,ext) # shutil.move(r, os.path.join(dirsortedpath,ext)) see if its what you want. If yes, then the shutil.move should not be the problem. sorry but i get an error message. print "Moving " r , " to ", os.path.join(dirsortedpath,ext) ^ IndentationError: unident does not match any outer indentation level ####BOF import os import shutil root="C:\\" dirsortedpath=os.path.join(root,"TEMP","batch","root","sorted") # put sorted path here dirunsortedpath=os.path.join(root,"TEMP","batch","root","unsorted") # unsorted path os.chdir(dirsortedpath) dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ] for r,d,f in os.walk(dirunsortedpath): for files in f: ext=files[-3:].lower() #get the extension if ext in dirsorted: try: print "Moving " r , " to ", os.path.join(dirsortedpath,ext) # shutil.move(r, os.path.join(dirsortedpath,ext)) except Exception,e: print e else: print "moved .." ###EOF I am using Nano to add or change a line of the python script. Python is particular about indentation, so indent properly(use spaces, not tabs) Code: [Select]import os import shutil root="C:\\" dirsortedpath=os.path.join(root,"TEMP","batch","root","sorted") # put sorted path here dirunsortedpath=os.path.join(root,"TEMP","batch","root","unsorted") # unsorted path os.chdir(dirsortedpath) dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ] for r,d,f in os.walk(dirunsortedpath): for files in f: ext=files[-3:].lower() #get the extension if ext in dirsorted: try: print "Moving " r , " to ", os.path.join(dirsortedpath,ext) #shutil.move(r, os.path.join(dirsortedpath,ext)) except Exception,e: print e else: print "moved .." thanx i didn't know,... i am not that familiar with python scripting. but now i got this,... print "Moving " r , " to ", os.path.join(dirsortedpath,ext) ^ SyntaxError: Invalid syntax i greatly appreciate your help and patience. Quote from: mazhive on September 09, 2010, 05:21:08 PM thanx i didn't know,... i am not that familiar with python scripting. sorry, it should be Code: [Select]print "Moving ", r , " to ", os.path.join(dirsortedpath,ext) Now proceed to look at the Python documentations. Take the tutorial if you are not familiarthanx ,... hmm i feel like stupid right now ,.... now it doesn't move anything. and no error... Quote from: mazhive on September 09, 2010, 06:13:35 PM thanx ,... hmm i feel like stupid right now ,....of course it doesn't because the shutil.move line is commented right ?? Uncomment the line when you are ready to move, but in the meantime, just use the print statements to see if you have got the correct files And what does your output SHOW? If you have print statements in your script, it will show when you run the script. If it did not show, then it shows that the Code: [Select]if ext in dirsorted: is not executed. Like i told you, if you are not sure, put in print statements to show the execution Code: [Select].... for r,d,f in os.walk(dirunsortedpath): for files in f: print "now doing file: " , os.path.join(r,files) ext=files[-3:].lower() #get the extension print "Extension is ", ext ..... Just a question, will the folders only contain 1 file type?oke,.. well some TIMES it has 3 files but only 1 is important for me to decide the actual extensions would be ,t64 ,d64 ,crt ,p00 ,prg with these files, sometime a txt file or nfo or doc are within that folder but that does not make my decision to move it in a folder so these te1 or te2 are just for experimental environment so i can use it in my actual folder and files later. ghostdog... well thats the point it does do a output but doesn't move the folder now i put the other piece of code in it and it gives me output but no moved folders yet it moved the files. ###BOF import os import shutil root="C:\\" dirsortedpath=os.path.join(root,"TEMP","batch","root","sorted") # put sorted path here dirunsortedpath=os.path.join(root,"TEMP","batch","root","unsorted") # unsorted path os.chdir(dirsortedpath) dirsorted = [ d.lower() for d in os.listdir(".") if os.path.isdir(d) ] for r,d,f in os.walk(dirunsortedpath): for files in f: print "now doing file: " , os.path.join(r,files) ext=files[-3:].lower() #get the extension print "Extension is ", ext for r,d,f in os.walk(dirunsortedpath): for files in f: ext=files[-3:].lower() #get the extension if ext in dirsorted: try: print "Moving ", r , " to ", os.path.join(dirsortedpath,ext) shutil.move(r, os.path.join(dirsortedpath,ext)) except Exception,e: print e else: print "moved .." ###EOF |
|
| 264. |
Solve : Change drive in CMD? |
|
Answer» I can't change drive by using D: It keeps saying my syntax is not in order What does it say exactly? Is your keyboard OK? Is the layout SETTING right? Can you type colons? like this ::::::::::::::::::: Do you see them on the screen? ANOTHER way to change drives is to use CD with the /D switch, Does this work? Code: [Select]D:\>CD /D C: c:\> Ha! It was a keyboard settings thing. I bought this thing in Colombia, I'm not exactly Colombian. Tnx for the help. |
|
| 265. |
Solve : If statements in command line? |
|
Answer» Hi, from %%G after the query executes. That does not set the value; it echoes %BATCH_QUERY%, a colon, and WHATEVER %%G happens to be. If you did not do SET BATCH_QUERY= before, it will be undefined (blank). So,should it be like this...... set BATCH_QUERY=0 set BATCH_QUERY=for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do echo %%G Quote from: priyabala on September 20, 2010, 02:58:22 PM So,should it be like this...... If you want the output of the sqlcmd command to be assigned to the variable BATCH_QUERY you could do something like this Code: [Select]for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do set BATCH_QUERY=%%G is it going to be a number? Sorry about the delayed reply. Yes, it is going to be a number. Also,can you please let me know how to do multiple conditions in if statments.Is this correct. if %ERRORLEVEL% equ 0 if %BATCH_QUERY% gtr 0 (GOTO LASTSTEP) if %ERRORLEVEL% NEQ 0 (GOTO ERROR1) Please let me know.I really appreciate your help on this. Thanks. Code: [Select] REM put this test FIRST if %errorlevel% neq 0 goto error1 REM You will only get here if errorlevel is 0 if %batch_query% gtr 0 goto laststep REM If you get here errorlevel is 0 and batch_query is 0 REM What are you going to do? REM Maybe goto end? REM If you do nothing you will go to the next line. REM Which is laststep... :laststep REM Your code goto end :error1 REM your code :end Also... in your code... Code: [Select]echo %JOBNAME% Abended REM THERE WAS AN ERROR! SET CONTROLM=1 goto END :END 1. The goto END statement is superfluous, because you are going there anyway. 2. "Abended" is not an ENGLISH word. Thanks for all your replies.I'll try these.I have always found life easier if a script commences ECHO OFF or even ECHO OFF I rather doubt that there is any benefit from starting with ECHO ON Alan |
|
| 266. |
Solve : can a *.bat answer prompted the questions automatically for a program?? |
|
Answer» I'm trying to make a batch file that will answer prompted questions automatically for a program. I need to click "next" 4 times and click "enter". Quote from: DaveIsRacerX on September 17, 2010, 07:42:21 PM I'm trying to make a batch file that will answer prompted questions automatically for a program. I need to click "next" 4 times and click "enter".Batch operates with a COMMAND LINE Interface. There is no way to click things with just batch. You will probably be able to ACCOMPLISH this with VBS, but not batch. Quote from: DaveIsRacerX on September 17, 2010, 07:42:21 PM I'm trying to make a batch file that will answer prompted questions automatically for a program. I need to click "next" 4 times and click "enter". Clicking "next" and "enter" sounds like you're DEALING with a GUI. Batch language barely knows Windows exists much less interacting with it. It is possible to create a response file for a command line program using redirection. For a Windows program you can use VBScript and program the keys (no mouse movements) needed to accomplish the task. There is a discussion of this going on in this thread. Check it out. Good luck. |
|
| 267. |
Solve : What values does the IF command compare?? |
|
Answer» Win XP Home. Batch script. |
|
| 268. |
Solve : Student stuck with batch files taht will not work, HELP? |
|
Answer» I have created several BATCH programs and saved them in a directory, updated my search PATH to include directory, and whenever i am in a different directory, the batch files do not WORK, why?1. What do you mean they "don't work"? Do you mean you cannot start them by typing the batch name, or that you can start them but they don't work in the WAY that you want them to? |
|
| 269. |
Solve : ftp commands? |
|
Answer» Hi all, |
|
| 270. |
Solve : ms dos computer has 2 lost allocation units? |
|
Answer» Hello, so here is where I should be able to type and I can't. It will not let me do anything, so I restart computer Is it a USB keyboard. Sometimes you have to go into the BIOS and enable Legacy USB for it to work.Yes, I do have a USB keyboard, will try. Thank you, I am running a PC DOS, don't know if it MAKES any difference.Sounds like System files are corrupted. You'll have to boot to a Boot Disk and reinstall system files. Get the version you need from here: www.bootdisk.com Boot to the floppy disk or CD. Then type: sys c: Hit return. Remove boot disk and restart computer. |
|
| 271. |
Solve : File name problem...? |
|
Answer» I have a batch file "Test.bat": I am sure a script can detect itself, Simply opening a file doesn't constitute "in-use". The call to CreateFile() would need to explicitly lock the file, by not specifying any of the FILE_SHARE_X flags. For example, if the CreateFile() is passed FILE_SHARE_READ, other programs can open the file for reading, but cannot write to the file or open it with write flags, or delete the file. FILE_SHARE_WRITE will allow programs to write to the file but not read or delete it, and FILE_SHARE_DELETE will allow the file to be deleted. Larry Osterman writes about this, and although he doesn't explicitly note anything to do with batch files there is an implication there; he notes that by default, DOS applications would open files in a manner so that any other program could access them, because of the single-tasking nature of DOS nobody considered this to be a problem. Therefore it's safe to assume that CMD.EXE opens batch files in the same mode that command.com does- that is, in a mode whereby the file is free to be changed (FILE_SHARE_WRITE+FILE_SHARE_READ+FILE_SHARE_DELETE). He also mentions that the NT Loader will open Executables with the FILE_SHARE_DELETE flag; this means that the file cannot be opened for READ or WRITE access by any program. additional invocations of the executable don't cause a problem, because the loader simply uses the same Mapped View of the executable file that it created the first time around. It's not as cut-and-dried as "if the file is open, no other program can access it". Wether that is truly the case for cmd, I don't know. It's entirely possible it opens the batch file, reads the next line, and then closes it, too.Sorry, you are right and I was wrong. I was remembering past experiences before CMD.EXE and before Windows 98, possibly back in the days of DOS v3.?, and I learnt then to expect grief from a *.BAT script if it tried to alter itself. I assumed the same was true now. My more recent experience with XP is that the O.S. may complain that a file is in use when I try to delete it, so I thought my old memories still applied. Sorry Regards Alan Quote from: ALAN_BR on September 25, 2010, 02:03:18 AM I was remembering past experiences before CMD.EXE and before Windows 98, Alan, this is just my 2 (euro) cents WORTH, but I don't really think you have any reason to apologise or say 'sorry' to anybody over this. You may have been inaccurate to say that a batch script is prevented from modifying or deleting itself, but you are certainly correct in your recollection that writing self-modifying code can be a risky business. A script that cuts the legs from under itself can lurch to DESTRUCTION. Having said that, self-modification is not always a bad thing. There is a good summary here http://en.wikipedia.org/wiki/Self-modifying_code As Wikipedia notes, "Because of the security implications of self-modifying code, all of the major operating systems are careful to remove such vulnerabilities as they become known. The concern is typically not that programs will intentionally modify themselves, but that they could be maliciously changed by an exploit." and "Self-modifying code is also sometimes used by programs that do not want to reveal their presence — such as computer viruses and some shellcodes. Viruses and shellcodes that use self-modifying code mostly do this in combination with polymorphic code. Modifying a piece of running code is also used in certain attacks, such as buffer overflows." In this regard, I am curious about the intentions of the OP. Thank you Salmon I remember the good old days when an anti-virus was pleased with itself if it could find and delete a suspect batch file. The I.T. department chose one that excelled in deleting any batch file that had the command FORMAT C:\ I had problems with self modifying code. I created a batch file called CD#.bat which LOOKED for arguments, and in the absence of arguments would skip to the end and execute the final line, which was something like CD C:\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\z\ If it was given the argument '#' it would alter the final line to aim at whatever the current path was, and the next day I immediately returned to yesterday's weird and wonderful directory with CD# Typically the new path was one extra 'z\' I tried to design self modifying code but failed. I finished with a "template" which CD#.bat duplicated as CD#.TMP The template was identical to CD#.BAT excepting the final line was "CD " without any CRLF or CtrlZ, then CD#.bat invoked CD >> CD#.TMP Then CD#.BAT deleted itself and renamed CD#.TMP as CD#.BAT That at least was the result I wanted, but achieving the result involved the use of intermediate scripts. The purpose of C:\z\z\z\z\z\z\z etc was that the first z\ held the first stage of a software product, and successive z\ held the previous plus a new feature, and the final z\ held the final product with all features. If a feature was found to be broken it was easy to test its operation at each z\ to identify what broke it and then fix it. This was when CVS etc version control was not available, and every man had to "roll his own". I remember the aggravation when the I.T. dept changed to an anti-virus which deleted my master template. It assumed that any *.BAT was up to no good and had to be deleted if it had a final command without a terminating CRLF I remember the wonderful feeling of revenge when the IT department went round one night with a FAST application to detect any unlicensed software, and the FAST application choked when it ENCOUNTERED my path with 80 or more 'z\' in a line. (I forget what the character length was for a command.com command, but I took my path up to the limit) This is a memory worth keeping ! ! Regards Alan |
|
| 272. |
Solve : Batch File, moves only jpg? |
|
Answer» Hello all. C:\Users\******\Documents\Batch Testing 2\File Sort testing Does this folder actually exist? Quote from: Salmon Trout on September 23, 2010, 03:44:25 PM Does this folder actually exist? Yeah, the ***** is my name so I did that Quote from: mat123 on September 23, 2010, 03:22:01 PM Try Thisnope. got this C:\Users\******\Documents\Batch Testing 2\File Sort testing>move *.JPG C:\ Users\*******\Documents\"Batch Testing 2"\"File Sort testing"\*.* The syntax of the command is incorrect. C:\******\Documents\Batch Testing 2\File Sort testing>pause Press any key to continue . . .The quotes need to go around the whole path Code: [SELECT]move *.JPG "C:\Users\******\Documents\Batch Testing 2\File Sort testing" this should do it Graham Quote from: gpl on September 24, 2010, 12:32:52 AM The quotes need to go around the whole path Success When I was added the path for the source it " syntax of the command is incorrect." however when I ran it in the source folder it works fine. |
|
| 273. |
Solve : secure problem in ftp? |
|
Answer» Hello EVERYBODY, |
|
| 274. |
Solve : QBasic Help!? |
|
Answer» I needed help with a question for my class, QBasic Programming. This is the question. |
|
| 275. |
Solve : Convert Tiff file only if condition applies? |
|
Answer» Hello fellow msdos coders, I wish I could do this with python or some other uncluttered language, but it has to be dos... I thank you in advance for any input. You could pipe the output of identify to find.exe and use the && (success) operator to decide whether to run convert thanks, it does the trick!Ahah, so I have a little more WORK on that script, right now it works, but instead of using a prefix, I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop! Any ideas? Code: [Select]for /r %%a in (*.tif) do identify -verbose "%%~fa" | find "Adobe RGB (1998)" && mkdir "%%~pa/sRGB" && convert -profile AdobeRGB1998.icc -profile sRGB.icm "%%a" "%%~pa/sRGB/%%~na.tif" Copy them into a folder outside the tree being walked by FOR /R, or instead of FOR /R you can use FOR /F to parse the output of 'dir /b /s *.tif', use %%~pa to identify those tifs not in the converted folder, which you convert and move. Quote I'd like to copy my newly converted files into a subfolder, unfortunately it gets processed as well, resulting in a neverending loop! But don't the converted files have a different profile? How do they get processed twice? |
|
| 276. |
Solve : emails with batch files? |
|
Answer» i need to send emails with the help of using batch files. how can i send the mails with batch files.Have you tried the search function on this site, I know it has been answered beforeFor use in batch files you can use Blat or MailSend. |
|
| 277. |
Solve : Returning the date and time on file? |
|
Answer» I picked up this CODE from Salmon Trout from another post. When I look at files on my desktop the date and time are echoed fine. When I TRY to look at files on another drive or a server I get no echo at all. When I get the full listing I have the file names and dates and times as you have shown. If you can show me (by copy and paste) the format of such a listing I can tell you how to extract the date and time information. I need to see this to know the character positions. It looks from your code as if you require the date and time of the last (LATEST) file in the folder. Here it is Volume in drive C has no label. Volume Serial Number is 984C-4C03 Directory of C:\D_Drive\workspaces\0102\batch\gisdb\wad 10/07/2010 10:39 AM . 10/07/2010 10:39 AM .. 10/28/2009 03:34 PM 193 0102bsav.addr 09/16/2007 03:32 PM 193 0102bsav.bld 08/10/2010 11:30 AM 1,543,341 0102bsav.dbf 08/10/2010 11:30 AM 2 0102bsav.lab 10/28/2009 03:34 PM 193 0102bsav.sub 10/05/2010 08:48 AM 50,684 0102ds.addr 10/28/2009 01:33 PM 288 0102ds.alt 09/16/2007 03:32 PM 193 0102ds.bld 10/06/2010 12:03 PM 1,234,550 0102ds.dbf 10/06/2010 12:03 PM 2 0102ds.lab 10/06/2010 11:40 AM 9,278,082 0102ds.seq 10/01/2010 12:50 PM 19,634 0102ds.sub 10/07/2010 10:39 AM 0 myfile.txt 13 File(s) 12,127,355 bytes 2 Dir(s) 10,652,610,560 bytes free Code: [Select] echo off setlocal enabledelayedexpansion set dirname="S:\Test" set dirswitches=/a-d /od for /f "tokens=1-4* delims= " %%A in ('dir %dirswitches% "%dirname%" ^| findstr /v "File(s) Dir(s) Volume Directory"') do ( set fdate=%%A set ftime=%%B set AM-PM=%%C set fname=%%E ) echo File date %fdate% echo File time %ftime% %AM-PM% echo File name %fname% |
|
| 278. |
Solve : User-input in PC-DOS? |
|
Answer» Hello. I SOMETIMES boot my computer from a live PC-DOS 7.1 CD, but I've noticed that I can't USE 'SET /P' to take input from the user. When I TRY using 'CHOICE' it just says "Bad command or file name.' How can I do this? |
|
| 279. |
Solve : ethernet ipaddress keeps changing and won't let me on internet? |
|
Answer» RIght now I am using wireless on my WIndows XP. THis started happening recently when I switched over to RR cable from dial-up. THis is a 3 yr OLD Toshiba laptop. I have spent the last 4 weeks dealing with techs from both companies(RR & Toshiba) and the problem is still erratic. Sometimes it works and sometimes it doesn't. I have done all of their suggestions like going thru the ipconfig---release---and renew stuff. I went thru the one of taking out the battery, shutting it off, pushing the off swicth for 15 seconds waiting and putting it all back together. I tried a different Ethernet cord and it worked for about three days. I also did the RR thing of disconnecting the laptop power source/modem and turning it back on after counting the required number of seconds. I was about to try black magic when I ran across this site (I was learning about external commands). Retirement sucks when I cannot use my internet. Help. Please.Road Runner, not so beep beep? |
|
| 280. |
Solve : mass rename in MS-DOS? |
|
Answer» I have files existing with same names in the folders with date as display below Code: [Select] C:\2010-09-10 <==== folder arr1.jpg arr2.jpg arr3.jpg arr4.jpg c:\2010-09-09 <==== folder arr1.jpg arr2.jpg c:\2010-09-08 <==== folder arr2.jpg arr3.jpg arr4.jpg arr5.jpg arr8.jpg arr9.jpg arr10.jpg arr11.jpg c:\2010-09-07 <==== folder arr2.jpg arr3.jpg arr4.jpg arr10.jpg arr11.jpg c:\2010-09-06 <==== folder arr9.jpg arr10.jpg arr11.jpg c:\2010-09-05 <==== folder arr2.jpg arr3.jpg arr4.jpg arr5.jpg arr6.jpg arr7.jpg arr8.jpg c:\2010-09-04 <==== folder arr2.jpg arr3.jpg arr5.jpg arr6.jpg arr7.jpg arr8.jpg arr9.jpg arr10.jpg arr11.jpg c:\2010-09-03 <==== folder arr2.jpg arr3.jpg arr4.jpg arr5.jpg arr6.jpg arr7.jpg arr10.jpg arr11.jpg c:\2010-09-02 <==== folder arr2.jpg arr3.jpg arr4.jpg arr5.jpg arr6.jpg arr7.jpg arr8.jpg arr11.jpg c:\2010-09-01 <==== folder arr2.jpg arr3.jpg arr4.jpg I would like to rename those files as _.jpg. and move all the files in single folder CALLED All_pics The SrNo is a continous running number serial number. Code: [Select]C:\All_pics\ 2010-09-10_54.jpg 2010-09-10_55.jpg 2010-09-10_56.jpg 2010-09-10_57.jpg 2010-09-09_52.jpg 2010-09-09_53.jpg 2010-09-08_44.jpg 2010-09-08_45.jpg 2010-09-08_46.jpg 2010-09-08_47.jpg 2010-09-08_48.jpg 2010-09-08_49.jpg 2010-09-08_50.jpg 2010-09-08_51.jpg 2010-09-07_39.jpg 2010-09-07_40.jpg 2010-09-07_41.jpg 2010-09-07_42.jpg 2010-09-07_43.jpg 2010-09-06_36.jpg 2010-09-06_37.jpg 2010-09-06_38.jpg 2010-09-05_29.jpg 2010-09-05_30.jpg 2010-09-05_31.jpg 2010-09-05_32.jpg 2010-09-05_33.jpg 2010-09-05_34.jpg 2010-09-05_35.jpg 2010-09-04_20.jpg 2010-09-04_21.jpg 2010-09-04_22.jpg 2010-09-04_23.jpg 2010-09-04_24.jpg 2010-09-04_25.jpg 2010-09-04_26.jpg 2010-09-04_27.jpg 2010-09-04_28.jpg 2010-09-03_12.jpg 2010-09-03_13.jpg 2010-09-03_14.jpg 2010-09-03_15.jpg 2010-09-03_16.jpg 2010-09-03_17.jpg 2010-09-03_18.jpg 2010-09-03_19.jpg 2010-09-02_04.jpg 2010-09-02_05.jpg 2010-09-02_06.jpg 2010-09-02_07.jpg 2010-09-02_08.jpg 2010-09-02_09.jpg 2010-09-02_10.jpg 2010-09-02_11.jpg 2010-09-01_01.jpg 2010-09-01_02.jpg 2010-09-01_03.jpg Which version of MS-DOS are you running? Advice given may alter with the version. However, if you mean the Command Shell in Windows try the following: Code: [Select]ECHO off cls setlocal enabledelayedexpansion echo y | del all-pics\*.*>nul set nbr=1 if not exist all-pics\ md all-pics\ for /F "tokens=*" %%1 in ('dir /ad /b 2010*') do ( set folder=%%1 for /f "tokens=*" %%A in ('dir /b "!folder!"') do ( if !nbr! LSS 10 set nbr=0!nbr! copy !folder!\%%A all-pics\!folder!_!nbr!.jpg>nul if !nbr! lss 10 set nbr=!nbr:~-1! set /a nbr+=1 ) ) |
|
| 281. |
Solve : Variables in For Loops (And If statements)? |
|
Answer» It seems Variables I declare within a FOR loops (or if statements) are getting FORGOTTEN about RIGHT away. The %%A of the FOR head works fine throughout the loop but a simple |
|
| 282. |
Solve : %PATH% - Environment Looking for a PATH? |
|
Answer» Looking for a way to pull a directory out of the PATH environmental VARIABLE. Guess I'm more so looking for the drive letter. I know my path will CONTAIN \vision\bin ... I was thinking I could do a FOR loop but I'm just not getting it at midnight. Help is appreciated. |
|
| 283. |
Solve : Conditional sentence in MS-DOS? |
|
Answer» Hi, I'm not an expert in MS-DOS, that's the reason of my question. How could I PUT a conditional question in a DOS batch? |
|
| 284. |
Solve : How to copy files to two words name folder? |
|
Answer» Problem is: |
|
| 285. |
Solve : Getting duration of .wmv files using: dir >filelist.txt? |
|
Answer» Hi there, Does that work for .wmv's or just .mp3's? Yes. One would need to change the "if" test but that's not difficult at all. Quote from: ghostdog74 on September 15, 2010, 07:22:26 PM vbscript is it possible in your opinion to use that code in an asp vbscript PAGE? I try it changing the "WScript.Echo objPlayer.mediaCollection.add(strFileName).duration" line in Response.write(objPlayer.mediaCollection.add(strFileName).duration), but doesn't work... |
|
| 286. |
Solve : Batch file execution control? |
|
Answer» What KINDS of limits can be put on opening batch FILES? I want to MAKE a .BAT that can ONLY be opened by another, SPECIFIED .BAT file. I don't even want the file to be readable from notepad. How would I do this? And is it possible to limit whether a file will open in some programs, but not others? Quote I want to make a .BAT that can ONLY be opened by another, SPECIFIED .BAT file. Nope Quote I don't even want the file to be readable from notepad. Nope Quote And is it possible to limit whether a file will open in some programs, but not others? And nopeWell shoot! It was worth a shot... Thanks! kyle_engineer |
|
| 287. |
Solve : Trying to make a really simple batch file and failing? |
|
Answer» Like the subject says I'm having a hard time understanding the syntax of batch files. This one in particular from what I understand is quite simple but I'm having a *censored* of a time figuring it out. I'm just trying to turn off the echo of all commands in the batch program, set the background color to bright white, and the foreground color to black, specify a setting in the Windows environment for the DIR command so it displays directories and files one SCREEN at a time, in order by filename and then clear the screen. |
|
| 288. |
Solve : How to move files based on file size with batch file?? |
|
Answer» I need to check 10 different Source directories for files and move them to 10 different DESTINATION directories. However files over 50Mb I need to move to a BigFile directory and rename the EXTENSION to *.big. I'm new/rusty to batch files but I've created the following script that I can't SEEM to get working correctly. I'm using it in a windows environment. |
|
| 289. |
Solve : Combine Check Disk and Defrag into one Bat file, and get no error messages? |
|
Answer» I've been getting these error MESSAGES, using Scheduled Tasks to do Check Disk and Defrag on my two HARD drives: |
|
| 290. |
Solve : How to time stamp the text file?? |
|
Answer» Hi Friend, |
|
| 291. |
Solve : check for double quote in a string? |
|
Answer» Is it POSSIBLE to check for a double quote at the END of a string? |
|
| 292. |
Solve : Creating a batch file that copies sub-folders? |
|
Answer» I have a batch file that reads I would go with XCOPY or ROBOCOPY, in your batch file.http://www.mydigitallife.info/2007/05/07/robocopy-syntax-command-line-switches-and-examples/ Ducks that fly upside down quake up. |
|
| 293. |
Solve : copy emails? |
|
Answer» i want to create a batch file that will copy my emials and put them in TH foler they belong can you help?thanks ron Quote from: ron57 on October 18, 2010, 02:15:38 AM i want to create a batch file that will copy my emials and put them in th foler they belong can you help?thanks ron What email client are you using? How do you determine which email goes to what folder? I doubt you can do this with batch code. Need more info. i am using 9.1 aol thanks ronAOL is proprietary and I could not find an ActiveX SCRIPT Control which would be needed for scripting. You might be able to USE the sendkeys method in VBScript, but it can be haphazard and unreliable. I don't have AOL installed, so I won't be much help here. AOL Explorer and IE7 are similar, so you might be able to script the web side of AOL (that might be a major project and time consuming). For future reference, can you not setup RULES that dictate where incoming mail should be delivered? If incoming mail COMES from PersonA, send it to FolderA and if incoming mail comes from PersonB, send it to FolderB. If you need further help get back to us. Good luck. this is the probleblem i have subscired to many ad exchanges.i get mail from them all to give me points for advertising. i sepratley i need a batch file that saves the emails to the folders i create in aol 9.1?thanks roncan i just copy the emails to a misc folder then sort them out from there?can you send me a batch file that will copy those emails to any folder?thanks ron Quote from: ron57 on October 19, 2010, 07:56:28 AM can i just copy the emails to a misc folder then sort them out from there?can you send me a batch file that will copy those emails to any folder?thanks ron It's not that simple. Without a script control, you cannot create an AOL object. Without the object you cannot script the program. My guess is that you'll need to do this manually within the AOL environment. You should try Google. I found nothing useful, but you might. If you're referring to copying to an external folder, you might find some 3rd party software that can do extraction or export operations. Good luck. |
|
| 294. |
Solve : Changing the date when you run a program? |
|
Answer» Is there a WAY that I can CHANGE the date on my PC when I run a certain program? |
|
| 295. |
Solve : How do I run an .exe from CScript without creating a separate window?? |
|
Answer» All the examples I have found are like this: |
|
| 296. |
Solve : VBS - Replace String where not 0 or 1? |
|
Answer» I have a value "00000000" without quotes where I am adding a 1 to any of the positions if a value has changed in an input file but in some cases I will end up with a value of "00130012" but what I would like my end result to be is only 0(unchanged) or 1(changed) in any position ... in other works if the value is greater then 1 I want to change it back to a 1. I'm trying to figure out if the easiest way to do this would be a replace function of some SORT? I'm thinking there would have to be something simpler then a doing a split and checking each value. Or instead of the above is there a way to check the position of a digit within the value to see if ALREADY 1, if it is don't add again. I COULD do 8 counters for each position that if greater then 0 add 1 to the position but keeping track of a bunch of counters seems like a lot of work. why don't you show us your code so far? That would save one *censored* of a lot of time asking questions. Why don't you, instead of adding 1 to a position, check if the digit in that position is already changed to 1 and if it is, leave it alone? Ended up using counters to track if I had already added a 1 to that position. Not sure how to go about checking if the position already has a 1 within a number. I am wondering... what are you going to do when you get to more than 9 changes for any particular position? Whne the number of changes is no longer a single digit? But assuming you never reach that state, you could create an empty string go through your string e.g. "00130012" character by character for each character of your string, if it is an 0 add a 0 to your new string otherwise add a 1 to your new string. e.g. Code: [Select]MyString="00130012" NuString="" For i=1 To 8 If Mid(MyString,i,1)="0" Then NuString=NuString & "0" Else NuString=NuString & "1" End If Next REM NuString now reads 00110011 But why don't you just have an array with 8 elements, set them all to 0 initially and then it's easy to check if an element is 0 and if it is, change it to 1, and if it isn't 0, leave it alone. At the end read out the elements into a string like above. My messy code ... Code: [Select]Option Explicit ''''''''''''''''' '''''''''''''''''This script creates flat file for ORC research. ''''''''''''''''' Dim objOutputFile, s, objFS, objArgs, strInputFile, objFile, strOutputfile Dim objFSO, boolMatchCaseSensitive, objInputFile, intArgCount, s1 Dim Count, dater, Branchn, a Dim StrDate, StrTime Dim origBatch, origTrans, origOLD, origISN, origAUX, origRT Dim origwAUX, origACCT, origTC, origAMT Dim storBatch, storTrans, storOLD, storISN, storAUX, storRT Dim storwAUX, storACCT, storTC, storAMT Dim storAUXn, storRTn, storwAUXn, storACCTn, storTCn Dim strOutputFilePath Dim editFlds, stroutput Call intialize() Set objFS=CreateObject("Scripting.FileSystemObject") Const intForReading = 1 Const intForWriting = 2 Const intForAppending = 8 Set objArgs = WScript.Arguments 'strInputFile = objArgs(0) intArgCount = WSCript.Arguments.Count 'Check for at least first two arugments. First arugment is input, second is outputfile(DAT format) if intArgCount < 2 then MsgBox ("Need input file as first argument") MsgBox ("Need ouput file as second argument") WScript.Quit(99) Else strInputFile = objArgs(0) 'strOutputfile = "???.???" strOutputFile = objArgs(1) End If 'Check if Inputfile (argument1) exist, if not then exit with Error If objFS.fileExists(strInputFile) Then ELSE MsgBox (strInputfile & " does not exist") WScript.Quit(99) End If 'MsgBox strOutputFile 'Set objFile = objFS.OpenTextFile(strInputFile) If objFS.fileExists(strOutputfile) Then objFS.DeleteFile(StrOutputfile) strOutputFilePath = objFS.GetParentFolderName(strOutputfile) 'If Not exists(strOutputFilePath) then 'CreateFolder(strOutputFilePath) 'End If Set objInputFile = objFS.OpenTextFile(strInputFile, intForReading, False) 'Open Inputfile to read line by line (s variable in do loop) Set objOutputFile = objFS.OpenTextFile(strOutputFile,intForAppending, True) 'Open Outputfile and set append mode for writing to file Do While objInputFile.AtEndOfStream <> True s = objInputFile.ReadLine() If InStr (s,"Original") > 0 Then If Count <> 0 Or editFlds <> 00000000 Then If Count = 0 Then objOutputFile.WriteLine origISN & " " & "01" & " " & editFlds Else objOutputFile.WriteLine stroutput & " " & editFlds End If End If 'stroutput = "" 'Count = 0 'editFlds = 00000000 Call intialize() 'origBatch = Trim(Mid(s,1,7)) 'origBatch = Replace(origBatch, " ", "") 'origBatch = Replace(origBatch, " ", "") 'origTrans = Trim(Mid(s,7,8)) 'origTrans = Replace(origTrans, " ", "") 'origTrans = Replace(origTrans, " ", "") 'origOLD = Trim(Mid(s,15,9)) 'origOLD = Replace(origOLD, " ", "") 'origOLD = Replace(origOLD, " ", "") origISN = Trim(Mid(s,25,10)) origISN = Replace(origISN, " ", "") origISN = Replace(origISN, " ", "") origAUX = Trim(Mid(s,35,9)) origAUX = Replace(origAUX, " ", "") origAUX = Replace(origAUX, " ", "") origRT = Trim(Mid(s,44,11)) origRT = Replace(origRT, " ", "") origRT = Replace(origRT, " ", "") origwAUX = Trim(Mid(s,54,9)) origwAUX = Replace(origwAUX, " ", "") origwAUX = Replace(origwAUX, " ", "") origACCT = Trim(Mid(s,63,18)) origACCT = Replace(origACCT, " ", "") origACCT = Replace(origACCT, " ", "") origTC = Trim(Mid(s,81,7)) origTC = Replace(origTC, " ", "") origTC = Replace(origTC, " ", "") 'Not using DESCRIPTION at this time origAMT = Trim(Mid(s,99,14)) origAMT = Replace(origAMT, " ", "") origAMT = Replace(origAMT, " ", "") End If If InStr (s,"ChangedTo") > 0 Then 'storBatch = Trim(Mid(s,1,7)) 'storBatch = Replace(storBatch, " ", "") 'storBatch = Replace(storBatch, " ", "") 'storTrans = Trim(Mid(s,7,8)) 'storTrans = Replace(storTrans, " ", "") 'storTrans = Replace(storTrans, " ", "") 'storOLD = Trim(Mid(s,15,10)) 'storOLD = Replace(storOLD, " ", "") 'storOLD = Replace(storOLD, " ", "") storISN = Trim(Mid(s,25,11)) storISN = Replace(storISN, " ", "") storISN = Replace(storISN, " ", "") storAUX = Trim(Mid(s,36,10)) storAUX = Replace(storAUX, " ", "") storAUX = Replace(storAUX, " ", "") storRT = Trim(Mid(s,45,10)) storRT = Replace(storRT, " ", "") storRT = Replace(storRT, " ", "") storwAUX = Trim(Mid(s,55,9)) storwAUX = Replace(storwAUX, " ", "") storwAUX = Replace(storwAUX, " ", "") storACCT = Trim(Mid(s,63,19)) storACCT = Replace(storACCT, " ", "") storACCT = Replace(storACCT, " ", "") storTC = Trim(Mid(s,81,7)) storTC = Replace(storTC, " ", "") storTC = Replace(storTC, " ", "") 'Not using DESCRIPTION at this time storAMT = Trim(Mid(s,100,14)) storAMT = Replace(storAMT, " ", "") storAMT = Replace(storAMT, " ", "") 'MsgBox "origAMT:"& origAMT &"storAMT:"& storAMT If Count = 0 Then If origAMT = 0.00 And storAMT > origAMT Then 'objOutputFile.WriteLine origISN & " " & "00" stroutput = origISN & " " & "00" Count = Count + 1 ElseIf origAMT <> storAMT Then 'objOutputFile.WriteLine origISN & " " & "02" stroutput = origISN & " " & "02" Count = Count + 1 End If End If If origAUX <> storAUX And storAUXn = 0 Then editFlds = editFlds + 01000000 storAUXn = storAUXn + 1 End If 'If origRIC <> storRIC Then 'editFlds = editFlds + 00100000 'End If If origRT <> storRT And storRTn = 0 Then editFlds = editFlds + 00010000 storRTn = storRTn + 1 End If If origwAUX <> storwAUX And storwAUXn = 0 Then editFlds = editFlds + 00001000 storwAUXn = storwAUXn + 1 End If If origACCT <> storACCT And storACCTn = 0 Then editFlds = editFlds + 00000100 storACCTn = storACCTn + 1 End If If origTC <> storTC And storTCn = 0 Then editFlds = editFlds + 00000010 storTCn = storTCn + 1 End If If origAMT <> storAMT Then If Count = 1 Then editFlds = editFlds + 00000001 Count = Count + 1 End If End If editFlds = Right("00000000" & editFlds, 8) End If Loop objOutputFile.Close Set objOutputFile = Nothing Set objFS = Nothing 'WScript.Echo "Completed" WScript.Quit() Function intialize() editFlds = 00000000 ' ^Empty SERIAL RIC(Pos44) TR FLD4 AMT TC AMT Count = 0 storAUXn = 0 storRTn = 0 storwAUXn = 0 storACCTn = 0 storTCn = 0 End Function An array isn't a bad idea, considered it but as you can see above still very messy. |
|
| 297. |
Solve : Vista copy command failure? |
|
Answer» Vista Home edition: The SYSTEM cannot find the path specified.That indicates to me that when the batch is "Run as Administrator" it somehow LOSES it's ability to see the current drive (the USB drive), it then is unable to find the path. Is there any way to avoid this when running a batch file "as Administrator"? Or is there a way to use an environment variable that would specify the correct drive letter of the USB drive for me?I think "Run as administrator" changes the current directory. If you put the line... echo %cd% ... at the start of your batch you will see what it reports when run as ordinary user and as administrator. However there is a way around this - every batch file knows its own drive letter, path and name and some more stuff besides. The variable %0 holds the information and you can use the standard d,n,p,x, etc variable modifiers to extract it. You put a tilde (~) and a letter after the percent sign. For example %~d0 holds the drive letter and colon. You can use upper or lower case letters but the convention is to use lower case. So you could put Code: [Select]copy "%~d0\MiscDLLs\*.*" "C:\MyProgram\" Note that the directory, path, etc obtained this way refer to the actual drive that the batch is stored on and do not change, and are independent from the current directory that the batch is being run from, so I expect that this will be suitable for your purposes. This is IDme.bat. It is on a pendrive which has the letter G, in the root directory... Code: [Select]echo off echo Drive letter %~d0 echo Folder %~p0 echo Name %~n0 echo Extension %~x0 echo Drive\path\name %~dpnx0 echo fully qualified path %~f0 echo File date %~t0 echo File size in bytes %~z0 pause I double click on it in Explorer and I see this in the command window that opens... Code: [Select]Drive letter G: Folder \ Name IDme Extension .bat Drive\path\name G:\IDme.bat fully qualified path G:\IDme.bat File date 18/10/2010 06:25 PM File size in bytes 291 Press any key to continue . . . The variable modifiers also work on parameters %1 to %9 passed from the command line, as well as the FOR variables %%a - %%z and %%A - %%Z, and you can see a list in the FOR documentation obtained by tyoing FOR /? at the prompt. The date is shown according to your local settings. I'm sure that will work. It's exactly what I was looking for! Thanks! This is definately a keeper. I've already thought of a few other applications for the information you provided. Thanks again! |
|
| 298. |
Solve : download xls from a webpage with a batch file? |
|
Answer» Hi, |
|
| 299. |
Solve : Create a folder prior to moving files?? |
|
Answer» I GOT the following code: |
|
| 300. |
Solve : dhcp devices? |
|
Answer» Hi CH, |
|