| 1. |
Solve : I want to create batch program with the script bellow. Please help me.? |
|
Answer» Hello everybody, One, really I didn't mean it as more than a rhetorical question. I should have said so. Quote from: tomycao on June 11, 2015, 07:51:04 PM This is not homework? This is the job I assigned. I don't mean to make mountains out of molehills either but how come you have this job and don't have the knowledge to solve it? I would still consider this a trivial question set by a school. To Mods: Should we avoid commenting on things in this way, when the task seems like they are avoiding learning what should have been discussed in class already? I'd hate for the good name of the forum to be devalued by my fairly irrelevant comments - I can simply ignore such threads if that is preferable. It would seem the OP has a job that requires him to you the one-line batch command to move a file. But he finds that operation throws an error. In many real world jobs the issue is to fix errors, not write programs. Maybe this outline represents what he wants to do. Fetch a file name from souse list. If target directory does not have that file Begin If source file not busy, move it to target Else complain end. If more in list, repeat. The above is NOT batch code. It is a way of humans expressing a possible solution. Some IT PROS find that need to spend as much time on an outline as the actual code. OP, does this represent your problem? This may help. Code: [Select]echo off set folderA=Put Name Of Source Folder Here set folderB=Put Name Of Target Folder Here for /f "delims=*" %%i in ('dir /b %folderA%\*.txt 2^>^&1') do ( if /i "%%i" EQU "File Not Found" ( echo No .txt Files In Folder A goto :eof ) if not exist %folderB%\%%i ( move "%folderA%\%%i" "%folderB%" > nul echo %%i Moved To %folderB% ) else ( echo %%i Exists In %folderB% ) ) Save the script with a .bat extension and run from the NT command prompt. Be sure to put valid paths in the two set statements at the top of the script. Quote This is not homework? This is the job I assigned. We don't help you do your job either... Quote from: patio on June 12, 2015, 04:11:19 PM We don't help you do your job either...Exactly. We do it for nothing, in our spare time and the OP who got a job by lying at the interview about their IT skills gets a. the CREDIT b. gets paid for our work and the worst part: c. probably doesn't understand why we object, just like the students who think that "research" includes posting "write my code for me" on forums. Now that sidewinder has raised the bar and gone to the effort of providing code, it's fun to give it a go in a different way. Code: [Select] echo off set "folderA=c:\folder" set "folderB=d:\folder" if not exist "%folderA%\*.txt" echo Give me my money back, there are no txt files here&goto :EOF for %%a in ("%folderA%\*.txt") do ( if exist "%folderB%\%%~nxa" ( echo "Filename already exists, can not move" ) else ( move "%%~a" "%folderB%" ) ) I just thought... maybe I'm a hypocrite (see my post above) because when I am stuck for a bit of code I will happily search Stack Exchange... Quote from: Salmon Trout on June 13, 2015, 04:52:29 AM when I am stuck for a bit of code I will happily search Stack Exchange... There's no hypocritical comment or shame in that - you're a capable coder and saving time instead of reinventing the wheel. Those people, and I shouldn't point the finger at the OP here, but there are so many bods who ask for code about elementary tasks that are quite likely to be coursework, and they aren't learning the skills to create code for themselves in the first place. Can you imagine what software of the future will look like when so many people copy and paste code that *might* do the job together, but they don't really follow what is going on and - bug city will be the new normal. Maybe it won't be quite that pronounced, and maybe the people asking are doing a course which just NEEDS this coding as a requirement, and will never code again. It's still lazy IMO and too often there is no thank you, or the same question is pasted onto 23 forums and there is still no followup. Oh, BTW, have I run out of rant-time yet? Quote from: foxidrive on June 13, 2015, 08:57:13 AM No, you have roll-over from last month. Dear Geek-9pm, Thank you for your explanation. I'm not a programmer, so my problem has description is not good . Best regards Quote from: Geek-9pm on June 12, 2015, 10:06:45 AM It would seem the OP has a job that requires him to you the one-line batch command to move a file. But he finds that operation throws an error. |
|