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.
| 7151. |
Solve : making programs witch run on ms dos? |
|
Answer» yo, |
|
| 7152. |
Solve : rename multiple files? |
|
Answer» im trying to rename multple files ina folder but keep the existing name and jsut add a word in the front. so for example Thanks alot it worked perfect. i had one more question can you exaplin what each part is doing? like what does "%~nx0" stand for? i know that the %%A is a varabile for the loop. but im trying to break down the code to understand everything its doing. if you can break it down that would be great. thank you again I see you NOTICED the echo that I left in for debugging. for /f "delims=" %%A in (dataset) ... the /f switch tells FOR to treat (dataset) as a source of lines to be processed. If dataset is a command enclosed in single quotes then the command is executed and the output is processed. the command is : dir /a-d /b *.* ... list files, but not directories in bare format ^| find /v "%~nx0" ... PIPE the output of dir through find (the pipe symbol is escaped with a CARET if used in a FOR dataset). The /v switch says to find.exe, "show lines which do not contain the search string". ... the search string for find.exe is %~nx0. %0 is the batch file name. The ~n and ~x modifiers mean "name" and "extension" so the batch file being run is filtered out of the file list produced by DIR, and thus the batch itself is not renamed. The other variable modifiers used in the script are ~d ~p, drive and path respectively. %%~dpnxA is the full drive letter, path, name and extension of each file listed by DIR %%~nxA is the bare name "cp %%~nxA" is the new name - that is, the original name and extension, with cp and a space in front of it. to learn more about DIR. FOR, FIND, etc, type the command followed by /? and read the help. thank you so much .Quote from: foxidrive on October 24, 2012, 04:28:02 PM . HuH ? ?I was going to suggest a simpler method - only then I realised it wasn't a filespec of test*.* but the OP wanted *.* and my method wouldn't have been appropriate due to a bug in for-in-do. We used to be able to delete posts, but that ability was removed? So I edited it. Now i'll know what the period means foxidrive... The feature just so you know was restricted due to a few posters that abused it incessantly...making many Topics almost un-intelligible. Thanx for the clarification. patio.Quote from: foxidrive on October 24, 2012, 05:44:33 PM We used to be able to delete posts, but that ability was removed? So I edited it. I have had to do this more than once. Sometimes I have managed to disguise the situation by hurriedly thinking up some other thing to post, more often I have just put a dot. |
|
| 7153. |
Solve : Residents services and program testing? |
|
Answer» Residents services and PROGRAM testing So you want a program that will check if your stuff is running and open it if it isnt? can we get a list of the programs and pathways to them? I use a very large list of residents under windows 7 64 bits, 16GB ram, i7 processor. I put a screenshot, and may be you can indicate the type of care I have to take in the bat I can add any other thing you require Best Regards Quote from: Squashman on October 25, 2012, 03:09:37 PM A slightly more concise option. Nice indeed. Goes well with programs in my data disks Y: or O: ? |
|
| 7154. |
Solve : Use Arguments in Batchfile!!!? |
|
Answer» Hello, |
|
| 7155. |
Solve : User Variable Question? |
|
Answer» I'm trying to add this user variable to a batch file and I'm having no luck. |
|
| 7156. |
Solve : unable to boot into windows 7 desktop? |
|
Answer» Hello, |
|
| 7157. |
Solve : Batch Delete? |
|
Answer» I am looking to create a batch that can will delete files permanently. |
|
| 7158. |
Solve : Escape character for " in IF DOS command? |
|
Answer» I'm trying to CONDITIONALLY remove a possible leading " character in a variable. I thought this would work: |
|
| 7159. |
Solve : Run dos program in XP? |
|
Answer» I know very little about DOS. I have an OLD program I would like to run through Windows XP. I copied it on my laptop and set up a batch file. It starts about 1 TIME in 20 attempts. Does anyone have any suggestions for me?Try to find "DosBox", and INSTALL it on your computer. |
|
| 7160. |
Solve : Displaying a message to screen with quotation & exclamation marks? |
|
Answer» Hi, Why not just toggle delayed expansion off before the echo and back on after the echo.If you're using variables with setlocal enabled, then those variables WOULD be wiped out once you did that. Too many people use an exclamation mark as if it was a period. That's true!! |
|
| 7161. |
Solve : batch file not working help please? |
|
Answer» hi all i am making this batch file show some system commands and i cant get it to work hi i cant work out why if i put yes or no it does yes on bothYou need to check the errolevel. Not if they answered Y or N. Code: [Select]C:\Users\Squash>choice [Y,N]?Y C:\Users\Squash>echo %errorlevel% 1 C:\Users\Squash>choice [Y,N]?N C:\Users\Squash>echo %errorlevel% 2 thanks got it hi hi do i set a count down timer ?Quote from: sjolliffe2 on January 10, 2014, 04:04:37 PM hi hi do i set a count down timer ? Try choice /? and study the options. Or use 'timeout'. If you want only the number, put it in a 'for /f' loop.@sjolliffe2 writing like that can LEAD to spaghetti code if you not careful. This author recomends using "subroutines". you could also try using a programming language if your env allows you to . vbscrtip/powershell included.Quote from: briandams on January 10, 2014, 06:21:15 PM @sjolliffe2To avoid this you could put :1 and :2 into the if statement, but that can cause many more errors. As long as you format the white space properly and add APPROPRIATE comments you can avoid this. Often times looking back on my previous codes I get lost in the "function" based ones easier than in the linear "spaghetti" ones.I think that how hard something to READ is more based off how documented it is, because it's the documentation that explains how things work, and the purpose of certain parts of the code... Spaghetti code just means that you have to spend time following the individual "threads" of spaghetti loop around the line numbers... It's more unclean than it is unreadable, though documented spaghetti code is harder to read than documented subroutine oriented code.... but that is only because of the fact that you have to keep track of your spaghetti at the same time as the code itself. (And that is BORING.)Top-Down programming is the term they used way back, for code that starts and then progresses linearly. It's useful for a small project and is easier to read in small projects, IMO. |
|
| 7162. |
Solve : How to create a batch command to change file names? |
|
Answer» Hi Hi foxidrive This is UNTESTED: it works in the same way. The REN commands will be placed in the file for you to examine. If you have files like 109-03 title.mp3 (without spaces between the numbers and hyphens) then you'll need another variation. Code: [Select]@echo off del renmp3.bat.txt 2>nul for %%a in (*.mp3) do ( for /f "tokens=1,2,3,* delims= " %%b in ("%%a") do ( for /f "delims=0123456789-" %%f in ("%%b%%c%%dA") do if "%%f"=="A" >>renmp3.bat.txt echo ren "%%a" "%%e" ) ) echo check renmp3.bat.txt for issues, if it's ok rename it .bat and run it. pause These solutions have worked great. Thanks for all the help. I have converted over 6500 names in a SECOND which as you can imagine was not a manual task I would have liked. Very very much appreciated. Thanks |
|
| 7163. |
Solve : Socket programming in dos? |
|
Answer» Hello, |
|
| 7164. |
Solve : Folder list? |
|
Answer» Hi, |
|
| 7165. |
Solve : Set part of a user's input as a variable? |
|
Answer» How do I set part of a user's input equal to a variable? but I'm not certain that a For loop is called for. What's the right way to do it?No, you don't need the FOR command at all as I have demonstrated. Either way works. Use what you feel comfortable with.Squashman - my apologies. I glanced at the first line of your command (which won't work for my application of the command) and disregarded it. Based on your follow-up I actually APPLIED the logic in a way that will work for me and it works (of course you knew that)! Learned something new from you today, thank you!Sometimes I just like to open the cmd prompt and run the commands one at a time to show the user the output. Sometimes the visual helps. But the base code is just: Code: [Select]SET /P UPN=Enter the users UPN: set upn=%upn:*@=%Of course I would do some error checking on the input so I would end up doing this. Code: [Select]:USERLABEL SET UPN= SET /P UPN=Enter the users UPN: IF DEFINED UPN ( set UPN=%UPN:*@=% ) ELSE ( GOTO USERLABEL )There are a few differences between these methods. I don't think that any of these scenarios will COME up in your example, by the way... If there is nothing before the @, the FOR method will return nothing, as it will read the @ as TABULATION, and the part of the string that you are looking for will be read as the first token, and ignored. The special expansion method would in this case select everything except the @. If the @ was followed by a second @, then the FOR method would eliminate the second @ as well, the expansion method wouldn't. If there was an @ somewhere else in the company name, then the FOR method would detect everything after that @ as the THIRD token, and exclude it, the Expansion method however would have already found the substring it was looking for, and would ignore the second @ Assuming that everybody using the script has a name, and that company names don't include the @ symbol, then either method will work FINE, however it seems that if you aren't going to add some more code to make it secure then Squashman's method is more secure. Also thanks Squashman, for that method. I'd never seen that used in place of for /f before.The asterisk only works as a wild card if it is the first character. It does not work in reverse and then you would need to use a FOR command to get the first token. |
|
| 7166. |
Solve : real easy question, probably? |
|
Answer» I'm STUCK in DOS and can't get back to windows the screen says C:\windows> What command do I type here to load up windows again. THANKS in advance |
|
| 7167. |
Solve : Patch file to copy a single file to multiple UNIX machine? |
|
Answer» Hello, |
|
| 7168. |
Solve : How to remove part of a string within a text file? |
|
Answer» Hi Hi If you want a new text file with line as in your text file, but with each line having the final 4 characters (.mp3) removed, a script like this should work @echo off setlocal enabledelayedexpansion set inputfile=birds1.txt set outputfile=birds-no-extensions.txt if exist "%outputfile%" del "%outputfile%" for /f "delims=" %%A in (' type "%inputfile%" ' ) do ( set oldline=%%A set newline=!oldline:~-0,-5! echo Old: !oldline! New: !newline! echo !newline! >> "%outputfile%" ) echo done pause birds1.txt Golden-bellied Euphonia.mp3 Golden-headed Manakin.mp3 Golden-spangled Piculet.mp3 Golden Collard Macaw.mp3 Golden Parakeet.mp3 Golden-winged Parakeet.mp3 Grassland Sparrow.mp3 Gray-*censored* Sabrewing.mp3 Gray-chested Greenlet.mp3 Gray-*censored* Martin.mp3 Gray-crowned Flycatcher.mp3 Gray-fronted Dove.mp3 Gray Monjita.mp3 Gray Hawk.mp3 Gray Antbird.mp3 Gray Antwren.mp3 Gray Rumped Swift.mp3 Gray-winged Trumpeter.mp3 Gray-headed Kite.mp3 Gray-headed Tanager.mp3 Gray-necked Wood-Rail.mp3 Grayish Mourner.mp3 Grayish Saltator.mp3 Great Jacamar.mp3 Great Kiskadee.mp3 Great Horned Owl.mp3 Great Tinamou.mp3 Great Rhea.mp3 Great Dusky Swift.mp3 Great Egret.mp3 Great Black Hawk.mp3 Great Antshrike.mp3 Greater Ani.mp3 Greater Thornbird.mp3 Greater Yellow-headed Vulture.mp3 Green-tailed Jacamar.mp3 birds-no-extensions.txt Golden-bellied Euphonia Golden-headed Manakin Golden-spangled Piculet Golden Collard Macaw Golden Parakeet Golden-winged Parakeet Grassland Sparrow Gray-*censored* Sabrewing Gray-chested Greenlet Gray-*censored* Martin Gray-crowned Flycatcher Gray-fronted Dove Gray Monjita Gray Hawk Gray Antbird Gray Antwren Gray Rumped Swift Gray-winged Trumpeter Gray-headed Kite Gray-headed Tanager Gray-necked Wood-Rail Grayish Mourner Grayish Saltator Great Jacamar Great Kiskadee Great Horned Owl Great Tinamou Great Rhea Great Dusky Swift Great Egret Great Black Hawk Great Antshrike Greater Ani Greater Thornbird Greater Yellow-headed Vulture Green-tailed Jacamar Thanks for the help. Works greatCode: [Select]@echo off set inputfile=birds1.txt set outputfile=birds-no-extensions.txt if exist "%outputfile%" del "%outputfile%" for /f "delims=" %%A in (' type "%inputfile%" ' ) do ( echo %%~nA>>"%outputfile%" )That's a more compact alternative, and the FOR part could be all on one line @echo off set inputfile=birds1.txt set outputfile=birds-no-extensions.txt if exist "%outputfile%" del "%outputfile%" for /f "delims=" %%A in (' type "%inputfile%" ' ) do echo %%~nA>>"%outputfile%" . |
|
| 7169. |
Solve : DOS 6.22 Hard Drive Issue? |
|
Answer» So I've recently acquired a stock Dell Latitude CP M233ST with a damaged hard drive. I cannot find a new drive for something this ancient, so I wish to use FDisk to partition off the damaged allocation units. I've partitioned a 10MB section using a Win98SE setup disk and now have my DOS 6.22 disk in the drive. These are CD-ROMs, not floppies, by the way. For some reason, though, FDisk will not read the internal HDD in DOS but will in the Win98SE disk. I've included the system info below. At this point I'm just looking for possible solutions to an unknown issue. |
|
| 7170. |
Solve : Adding/removing a prefix to/from file names? |
|
Answer» I'd like automate a bulk RENAMING task with just one click or with a command. I suppose I need command line utility or a batch file that allows me to do this. The changes in all couples are the same: adding a prefix "DM-" to the files NAMES in one case, and removing the prefix in the other so as to restore the original names. Could you help me out with this? Thanx. ADD PREFIX DM- TO CTF-*.* = DM-CTF-*.* Code: [Select] for /f "tokens=1-2 delims=." %%a in ('dir /b CTF-*.*') do ren %%a.%%b DM-%%a.%%b Quote REMOVE PREFIX DM- FROM DM-CTF-*.* = CTF-*.* Code: [Select] for /f "tokens=1-4 delims=-." %%a in ('dir /b DM-CTF-*.*') do ren %%a-%%b-%%c.%%d %%b-%%c.%%d You should be able to work out the rest. You may want to consider making a test run in a test directory before you blast away at real files. Good luck. Thanks for the information. It works as you say, however, I have batch of files with long names and space between. Can you please advice how I can add prefix to multiple files in one go? For example: "run dmc - walk this way.mp3" rename to: "2013 run dmc - walk this way.mp3" "NWA - Hello.mp3" rename to: "2013 NWA - Hello.mp3" Regards, FSamie (a rookie)for /f "delims=" %%A in ('dir /b /a:d') do rename "%%A" "2013 %%A" Is how I would do it, but I'm sure there are multiple ways that work.I think you meant /a-dTo support long filenames with spaces etc you just need the QUOTES in the ren portions. Quote from: SIDEWINDER on December 03, 2005, 04:10:03 PM Code: [Select]for /f "tokens=1-2 delims=." %%a in ('dir /b CTF-*.*') do ren "%%a.%%b" "DM-%%a.%%b" But it can be simplified too: Code: [Select]for /f "delims=" %%a in ('dir /b CTF-*.*') do ren "%%a" "DM-%%a" Code: [Select]for /f "tokens=1,* delims=-" %%a in ('dir /b DM-CTF-*.*') do ren "%%a-%%b" "%%b" Quote from: Squashman on January 04, 2014, 08:04:18 PM I think you meant /a-dYup, it's good to have people willing to look over your work for these kind of mistakes lemonilla and all you gurus here Thank you very much, you people are truly good. foxydrive I tried your code to remove the extension, but it didn't work. Can you please take my example and remove the 2014 from it? 2014 jz - 99 problems.mp3 2014 mj - walk that way.mp3 Code: [Select][quote author=FSamie link=topic=15956.msg898900#msg898900 date=1389110499] 2014 jz - 99 problems.mp3 2014 mj - walk that way.mp3 [/quote] Because 2014 is ALWAYS in the beginning, and we know that it is 4 characters long, we can set the file name equal to a string, and then remove the first 5 characters (to include the space as well). setlocal EnableDelayedExpansion for /f "delims=" %%A in ('dir /b /a:-d') do ( set a=%%A rename "%%A" "!a:~5!" ) [/code] I would recommend testing this on dummy files before you give it a go. I created a bat file with the following: for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A rename "%%A" "!a:~5!") but it didn't work. Give this a run. It will echo the commands to the console so remove echo if you are happy with it. Code: [Select]@echo off for /f "tokens-1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b" pause foxi I tried for /f "tokens-1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b" it didn't work. Please have in mind I'm an absolute rookie who just created a .bat file with your codes and tried to remove the "2014 " prefix from my files in a specific folder. Thanks in advanceQuote from: FSamie on January 07, 2014, 03:41:33 PM I created a bat file with the following: You forgot to enable Delayed Expansion Code: [Select]setlocal enableDelayedExpansion for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A & rename "%%A" "!a:~5!") (and your syntax was wrong after the 'do'. You had forgotten to separate 'set' and 'rename' with & or &&)Lemonilla I tried your codes and they all work fine and summarised here To add, for example "2014 " to all files: for /f "delims=" %%A in ('dir /b /a-d') do rename "%%A" "2014 %%A" To remove "2014 " from all files: setlocal enableDelayedExpansion for /f "delims=" %%A in ('dir /b /a:-d') do (set a=%%A & rename "%%A" "!a:~5!") Again, many thanks FSamie (beginner)Quote from: FSamie on January 08, 2014, 07:25:56 AM foxi It always helps to mention the error messages on the console - for future posts anyway. In this case I had hit - instead of = when I typed the code. Oops. Try this: Code: [Select]@echo off for /f "tokens=1,* delims= " %%a in (' dir *.mp3 /b /a-d ') do echo ren "%%a %%b" "%%b" pause |
|
| 7171. |
Solve : Getting multiple lines of output as arguments to another program?? |
|
Answer» Hi, I have an Acer laptop, running windows 7, etc. |
|
| 7172. |
Solve : Batch file to play different window startup sounds randomly? |
|
Answer» Hi The scipt is not working. My waves files are located at C:\Media. Change it to this line, now that it is echoing the random files. copy /b /y "%file%" "c:\Media\Sound1.wav" >nul and remove the pause |
|
| 7173. |
Solve : Help with File Open ErrorLevel in a DOS Batch? |
|
Answer» Hello, I've got a simple batch file that's running on a windows xp system and it's set to run a continuous loop looking for files to exist in a particular folder on my network DRIVE. The bat file basically consists of a bunch of IF EXIST commands see example below. Do I need to clean up the file I'm coping too so the next time this file Exists and the copy command is invoked there won't be a problem over writing that file.. Not sure what you mean here... Thanks again for your help.. I don't exactly understand what this command is doing COPY /B filename1+NUL filename1 > NUL 2>&1 && .. I see the COPY command so I assume that it's creating a file somewhere on my network drive so I was wondering if I needed to DELETE the copied file to keep the drive cleaned up to prevent other issues like over write errors etc the next time the loop condition exists.. Sorry for the dumb questions...There are no extra files produced. The way the test works is this: What you are doing is copying each file onto itself. Normally you cannot copy a file to another file in the same folder with the same name. You get an error, "The file cannot be copied onto itself." You can try it yourself at the prompt. Say you have a file called test.txt. If you do... copy test.txt test.txt you get the error. So you use a trick. NUL is a special empty file available in may operating systems including Windows. So you use the COPY file1+file2 file3 syntax, where the + sign means copy file1 and file2 to file3. The trick is that NUL is an empty file so copying file1+NUL to file2 just makes a copy of file1 in file2. A further trick is that this works if file2 already exists. So we copy file1+NUL to file1 (that is, itself, note the files are the same) We use the /B switch after COPY to force a binary (byte for byte copy) so that nothing in the file gets altered. If the file is not in use by another process, the operation succeeds and the file ends up the same as it was before. If the file is in use, the operation fails. We can test for failure or success using && and ||. command1 && command2 - only if command1 was successful (errorlevel 0) then command2 is executed. You have your loop going round and round testing if each file is in use. If it is in use, you would get an error message each time saying "The process cannot access the file because it is being used by another process." If the file was not in use, you would get a "1 file(s) copied" message. Either way, these would clutter up the screen each time so, using > we we redirect the console output stream to another instance of NUL (yes, you can do this!) also we use 2>&1 to redirect the (STDERR, stream 2) into the standard console stream (STDOUT, stream 1). So there are no messages on the screen. I know this may seem confusing, but you can look on the web for explanations of the COPY command, NUL, stream REDIRECTION, as well as the && and || operators.Thank you for the detailed explanation I really appreciate your time and effort... This is exactly what I was looking for.. Thanks again for all of your help and guidance.. ScottAnother option from Dbenham on StackOverFlow. http://stackoverflow.com/questions/10518151/how-to-check-in-command-line-if-given-file-or-directory-is-locked-that-it-is-usOne thing to be aware of is that in any multitasking operating system, there is no 100% foolproof way of knowing that a file is not in use, at the time you want to do something to it. You could do a check that comes back "not in use" and then, milliseconds later, before your script has a chance to do the next command, the file gets grabbed by another process. No matter how careful you are there is always a window between when you check if the file is available and when you actually use it. This may not pose much of a problem e.g. if you are looking to if an expected file exist in a folder, you find that it does, but the process that was writing it has not yet finished, and you know that after that happens, no other process is going to grab it. |
|
| 7174. |
Solve : Redirect output? |
|
Answer» Hi,
I could have made this clearer echo hello world >output.txt is equivalent to echo hello world 1>output.txt If you do this DIR /b *.txt >output.txt you will get a list of any .txt files in the current folder into output.txt BUT if there are none, the error message file not found is output to stream 2 and appears on the screen (because you have not redirected stream 2) so you can do this valid output to one file, errors to another file: dir /b *.txt 1>textfiles.list 2>errors.txt or everything in one file dir /b *.txt > textfiles.list 2>&1 If you need to echo a string to a file, white space before the redirection symbol is important if the string is a single digit (any digit 0-9) or there might be white space then a single digit number at the end of the string: C:\>echo my age is 1>test.txt & TYPE test.txt my age is C:\>echo my age is 1 >test.txt & type test.txt my age is 1 Thus echo %var%>file.txt will NOT give the same result as echo %var% >file.txt if %var% is a digit, or ends with a space then a digit C:\>set var=8 C:\>echo %var% 8 C:\>echo %var%>test.txt ECHO is on. C:\>echo %var% >test.txt C:\> Hi, Thanks for responding to my post. But, That didn't work. I did notice there is a wrinkle to the process. I run the utility from the command window, but it opens up another DOS window and the output shows up there. I'm not sure what is going on. ThanksAh. I didn't read your first post properly. I thought it said xcopy. Now I see you are using xxcopy, (which looks like a regular console program but isn't) I suggest you study the xxcopy documentation (the chm file) (in the downloaded installation zip archive) and the FAQs on the web site especially the logging options, which look like the /Oa and /On switches. |
|
| 7175. |
Solve : Modify Title for a lot of songs? |
|
Answer» Running Windows 8.1, been playing some Audiosurf. I have a lot of songs, but I found out I can add TAGS to them to alter gameplay http://www.audio-surf.com/forum/index.php/topic,3784.0.html. Is there a simple way to add text to the title of songs (like in file properties->details->title) without loosing the existing title or altering the filename other than doing manually? Are they MP3 format songs? MP3 can have tags at the beginning and END of the songs that have descriptions ETC with the beginning ID3 tags (V2.x) usually being the most commonly used these days. You can get COMMAND line TOOLS to modify the ID3 tags. |
|
| 7176. |
Solve : BATCH PROGRAM TO RETRIEVE FILES ON WINDOWS 7? |
|
Answer» i would like to CREATE a batch program that searches for .csv file in numerous folders on a directory. if the file is found in any folder it creates a new folder and PLACES all the files in it. i would like to create a batch program that searches for .csv file in numerous folders on a directory. if the file is found in any folder it creates a new folder and places all the files in it. Creates a new folder where? Do you want the files moved or copied into it? Quote from: example my path is U:/WED/processin_folders within this location there are over 300 folders. What do you want to do with the duplicates? i want the files to be copied to the home directory U:/WED create a folder called RESULTS, EACH FILE IN the each folder is dated so there should not be any duplicatesQuote from: dstyles on November 08, 2012, 09:05:16 PM i want the files to be copied to the home directory U:/WED create a folder called RESULTS, Ok.. Quote from: EACH FILE IN the each folder is dated so there should not be any duplicates If they have the same filename then they can't all be put in the same folder, without overwriting the one that was there already. If there were say 28 broward.csv files, how do you want to HANDLE them?we could rename each file example broward_1_(date) broward_2_(date) etc each in sequential orderThis is untested: click on it and type in your search term. It doesn't add the date to the filename as the filenames can already be sorted by date in your file viewer. It adds a number after the filename. 0 is the first one, then 1, 2, 3 etc. Code: [Select]@echo off set var= set /p "var=Type your search string for .csv files: " if not defined var goto :EOF set "source=U:\WED\processin_folders" dir "%source%\*.csv" /b /s /a-d |find /i "%var%">filelist.tmp for /f "delims=" %%a in (filelist.tmp) do call :NEXT "%%a" del filelist.tmp goto :EOF :next set c=0 md "%source%\Results" 2>nul :loop if exist "%source%\Results\%~n1_%c%%~x1" set /a c=c+1 & goto :loop echo copying %1 to "%source%\Results\%~n1_%c%%~x1" copy /b "%~1" "%source%\Results\%~n1_%c%%~x1" goto :EOFTHANKS I WILL TEST IT |
|
| 7177. |
Solve : Batch File to Remove a bracket and delete the line after the bracket.? |
|
Answer» Hi ,, |
|
| 7178. |
Solve : Batch file OR...? |
|
Answer» I need a program OR batch file to create empty text (.txt) files based upon the first file. |
|
| 7179. |
Solve : Parse file names and rearrange variables for new name? |
|
Answer» I'm trying to RENAME a group of files that are named like this "KSFO-AM 05 to 10 (KSFO) 11_13_12 02.mp3" where I want to parse the name by the spaces found in the name and then re-arrange the name. I'm trying to use the FOLLOWING command: |
|
| 7180. |
Solve : Creating Batch File...? |
|
Answer» Good Afternoon, Hello, if you have exhausted all possible ways, you can do your own progress bar through hardcore programming , or you could search for an already made tool that ties in to copying of files and showing you the progress. In the first place, if you want to see progress bar, it means you are not automating it? so another way is to search for GUI based "xcopy". to do your own hard core programming in your favourite language. Code: [Select]filesize = get total file size somesize = some KB value less than total file size while true do read file with somesize bytes display progress bar if somesize still less than filesize sizeleft = filesize - somesize check to see if all bytes is read from file. if all read, get out of loop done I have no idea about programming unfortunately I wish I did as most things I do would be so much easier....... I think I will leave the progress bar out but I have put echo on so it shows me what files its copying so I'll just stick with that for the time being. Thanks EVERYONE for all your help. Happy Christmas EmmaThis isn't perfect; you won't get a dialog sometimes for a short-time operation e.g. small number of files with no conflicts - You can use Visual Basic Script to show the Windows copy progress dialog 1. Save this script somewhere with the .vbs extension (e.g. CopyProg.vbs) Const FOF_CREATEPROGRESSDLG = &H0& strSourceFileSpec = wscript.arguments(0) strTargetFolder = wscript.arguments(1) Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(strTargetFolder) objFolder.CopyHere strSourceFileSpec, FOF_CREATEPROGRESSDLG Call it from a batch like this 1. To copy all files and subfolders from the folder C:\My Documents to the folder D:\Targetfolder (which MUST already exist) Note: On my system I need the \*.* after the source folder wscript "c:\scripts\CopyProg.vbs" "C:\My Documents\*.*" "D:\Targetfolder" 2. To copy one file from one place to another wscript "c:\scripts\CopyProg.vbs" "C:\batch\addup.cmd" "D:\batch" Remarks: You may find you only get a dialog for a long operation or if target files already exist; for one or a few small files from one local hard drive to another the copy happens too quickly; if target files already exist you will be asked for skip/overwrite/rename options. You don't need to include the full vbs file path if it is in the same folder as the batch script. Tested on Windows 7 Alternative: install something like Teracopy and study the command line options (may not be an option in a workplace computer) (You can make Teracopy replace the Windows file copy dialog) CopyProg.vbs syntax: [cscript|wscript] Copyprog.vbs [move|copy] source dest flags If no flags specified, there is a dialog for non-instant operations, and all file replace/overwrite options are presented to the user, in a dialog with a "Cancel" button. Use quotes around source and dest if they have spaces. Flags: 4 Don't display a progress box 8 Rename if target file already exists 16 Respond with "Yes to All "for any dialog box 64 Preserve undo information, if possible 128 Operate on files only if *.* is specified 256 Display a progress dialog but do not show file names 512 Don't confirm creation of new directory 1024 Don't display a user interface if an error occurs 2048 Don't copy security attributes 4096 Local directory only (no recursion) 8192 Only copy the specified files Examples: Wscript CopyProg.vbs copy "c:\batch" "D:\batch" 8 16 512 Cscript CopyProg.vbs move "d:\copysource\batch\001-999.txt" "E:\test" Code: [Select]iFlags = 0 For j = 3 to (wscript.arguments.count)-1 iFlags = iFlags + Cint(wscript.arguments(j)) Next strSourceFileSpec = wscript.arguments(1) strTargetFolder = wscript.arguments(2) Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(strTargetFolder) If lcase(wscript.arguments(0)) = "copy" Then objFolder.CopyHere strSourceFileSpec, iFlags End If If lcase(wscript.arguments(0)) = "move" Then objFolder.MoveHere strSourceFileSpec, iFlags End If |
|
| 7181. |
Solve : Help Needed with document copy and rename? |
|
Answer» Hello to everyone I have to add that i checked and found that it stacks on an htm file that has the "<>" on its name. They are illegal filename characters in Windows - but there are similar looking ones in Unicode. Unicode and foreign language characters are often problematic in batch files. You have to use the right code page with non-English characters, using the CP command in the beginning of the batch file, and if it is Unicode then that will fail in many ways with batch code. VB Script is a better choice there. It's also possible that your path\filename length is too long for some of them too. |
|
| 7182. |
Solve : Specific Key press detection? |
|
Answer» Hello there! |
|
| 7183. |
Solve : Exporting / Importing File names from https to Excel / Word? |
|
Answer» Quote from: foxidrive on November 16, 2012, 07:34:33 AM So you take you bat and ball and go home rather than work *with* the people that are SOLVING your problem - for free. Sir, I think I said I'm sorry and immensely thankful:)This will only work if all the files are .wav files. EDITED: to ADD a delims section Code: [Select]@echo off del "output file.txt" 2>nul for /f "delims=" %%a in (listofserialnumbers.txt) do ( for /f "delims=." %%b in ('find "-%%a-" ^< "list of files.txt"') do ( >>"output file.txt" echo %%b.wav ) )Quote from: foxidrive on November 16, 2012, 07:54:53 AM This will only work if all the files are .wav files. It definately did. Thanks again! |
|
| 7184. |
Solve : Batch Parser? |
Answer» QUOTE from: Lemonilla on December 19, 2013, 02:02:00 PM@echo off Thanks, that should provide me with the idea I need... should be able to get what I need from that. I just need it as a kind of error-handling... the script will be executed about once a day, so it'll take a few years to reach the max number. I just want to add that functionality soon, in case we all forget about that and a few years from now the SCANNERS won't recognise the barcodes because the numbers are too HIGH @patio: I adore words which aren't heard as often in modern times... @ghostdog: I learned some perl a few years back, but the computer on which this script is running is quite the oldtimer, so I don't want to impair the performance by adding further runtimes or so... that's why I want to try it using windows internal means... Quote from: rioc on December 20, 2013, 01:49:35 AM @patio: I adore words which aren't heard as often in modern times... I too have a love of English - crazy language that it is, with so many pitfalls for those learning it as a second language. Quote from: rioc on December 19, 2013, 05:20:58 AM Bligh me... I think you mean 'blimey' from the LAND of Mad Englishmen. Also, to make it easier to keep track of the number you are on, keep in mind you can do this: 'set /p a=<Text.txt' to grab the first line of a text file into %a%. |
|
| 7185. |
Solve : Batch file problem: is not expected at this time/moment? |
|
Answer» Hello, |
|
| 7186. |
Solve : Inconsistant results from batch file coding..? |
|
Answer» Hi all, |
|
| 7187. |
Solve : How to rename the file with file size? |
Answer» One of your % SIGNS is not doubled. Did you FIX that? |
|
| 7188. |
Solve : Trying to run a cmdline on a dir of 1500+ files? |
|
Answer» I'm trying to run a commandline call but I need the batch FILE to insert the FILENAME for each call. |
|
| 7189. |
Solve : Please Help Me (CMD Help)? |
|
Answer» Please I need a lot of help. Okay here's the problem I am able to log on to an account and it is on a domain called DETNSW.WIN UNLESS you are an administrator, you won't be able to do that. |
|
| 7190. |
Solve : copy screen? |
|
Answer» I am using the DOS promt in windows XP. My PROGRAM is very simple, it does a graphic in the total screen of DOS, I have to copy this graphic to a program like paint brush or corel draw to invert the colors. |
|
| 7191. |
Solve : Create folders based on part of a filename? |
|
Answer» I'm really pulling my hair out on this one. I collect PICTURES of motorcycles, hot rod cars (especially Mustangs), and racing boats. I use bulk file renamer to place them in the following format: |
|
| 7192. |
Solve : NET TIME /SET fails with "System error 5 has occured. Access is denied"? |
|
Answer» When I attempt to set the time as follows: |
|
| 7193. |
Solve : how to echo line both on screen and text file? |
|
Answer» I want to display the output both on screen and log.txt file Unlike most Nix systems there is not a native way to do this in batch. You can use the TEE command on most NIX operating systems to do this. I believe there is a Win32 port of it if you really want to do this. There are plenty of Tee.exe programs around, not to mention any number of Tee.bat. Tee.cmd and Tee.vbs scripts. The most cursory of Google searches will turn up plenty of results, which it would be both tedious and redundant to reproduce here. In particular searching the Google archive of alt.msdos.batch.nt using INTELLIGENTLY chosen search terms is a fruitful method of finding solutions. If the OP is using a business or school system where installation of third party EXECUTABLES is not allowed, then a cmd or vbs approach may be the only way. You can use: echo %%a >> log.txt echo %%a in one line, maybe use a pipe, fork, or do: echo %%a >> log.txt && echo %%a Thats your best option |
|
| 7194. |
Solve : Splitting a path using a string in DOS batch.? |
|
Answer» I am having a hard time figuring out how to split a string (a path) by another string. I ave SEEN a few posts regarding this, however, people are always splitting using a single character like a '\' for example. If you are using the CALL you do not need to use delayed expansion. You can double up your percents and it will still work fine. I spent about 30 frustrating minutes adding various numbers of percents and then gave up and went with delayed expansion. |
|
| 7195. |
Solve : Change default printer? |
|
Answer» Hi, |
|
| 7196. |
Solve : Batch Script for Reading text, removing and copying? |
|
Answer» Hi guys, |
|
| 7197. |
Solve : Help needed on renaming filenames with .bat? |
|
Answer» Hello forum users, so basicly you have 1 copy of a file named "head_x_bump.rx3" and you need to make a bunch of copies of it replacing x with a number? Exactly!I added a picture to as example. I have around 1500 head_x_0.rx3 files that need a corresponding head_x_bump.rx3 (of which I have one version that I need to copy with corresponding numbers). For exaple the head_260084_bump.rx3 is what I need to create. Problem is -as you can see- the numbers do skip. So basicly I'm LOOKING to make a copy of the head_x_bump and get the numbers from the head_260074_0.rx3 in the name of bump file at the position of the x This creates the extra files, using the numbers from the existing files. Code: [Select]@echo off for /f "tokens=2 delims=_" %%a in ('dir head_*_0.rx3 /b /a-d ') do type nul >"head_%%a_bump.rx3"Wauw, thnx!! It looks like it creates the files, but doesn't copy the original head_x_bump file. almost there My mistake - but it's a simple change. Code: [Select]@echo off for /f "tokens=2 delims=_" %%a in ('dir head_*_0.rx3 /b /a-d ') do copy "head_x_bump.rx3" "head_%%a_bump.rx3" >nulI tried the same, but now I see I added an unnecessary > Thnx a lot, it works! |
|
| 7198. |
Solve : Dos and ">>" switch? |
|
Answer» Wondering if some one can shed some light on how to use the >> switch. |
|
| 7199. |
Solve : use batch to change text file's font.? |
|
Answer» Is there a way to change the font of a text FILE? I want to take user input and WRITE a text file using a different font.There are no native BATCH ways to change word documents. There are no native batch ways to change word documents. Then they do exist, I'd just have to FIND one?*.txt (text) documents do not have included formatting for fonts, just PLAIN text.Quote from: Lemonilla on November 25, 2012, 06:03:52 PM Is there a way to change the font of a text file? I want to take user input and write a text file using a different font. Text files don't have fonts; this is something done by whatever program you are using to view the text file - Notepad for example. Quote from: Lemonilla on November 25, 2012, 09:39:56 PM Then they do exist, I'd just have to find one? They don't exist. |
|
| 7200. |
Solve : Make batch file FIND file extentions and in txt? |
|
Answer» how do i MAKE a BATCH FILE that finds FILES or files by extension then make it put results in txt?dir *.txt > log.txt |
|