| 1. |
Solve : A batch file do a automatic copying and renaming job with conditions like this?? |
|
Answer» Hello, I'm NEWBIE in command prompt console and want to ask something about my issue. I try some way to write a batch file do this job but unsucessfully. Pls someone help me out and pls write code in details (for my question, don't just tell me generally and tell me find out myself With an attitude like that, you'll never learn anything. Would have been better to post your unsuccessful attempt. It would have shown that you at least made an attempt for a solution. C:\batch>type winder122109.bat Code: [Select]@echo off set source=E:\MPEGAV set target=C:\Documents and Settings\%username%\My Documents cd %target% dir *.dat rem del *.dat ( remove "rem" if you need to remove .dat files ) for /f %%x in ('dir /b %source%\*.dat') do ( for /f "tokens=1-4 delims=:." %%i in ("%time%") do ( if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat" ) else ( copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat") ) ) cd %target% dir *.dat Output: C:\batch>winder122109.bat Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of %target% 12/21/2009 11:18 AM 9 me.dat-17320759.dat 12/21/2009 11:18 AM 9 me2.dat-17320759.dat 2 File(s) 18 bytes 0 Dir(s) 305,583,677,440 bytes free 1 file(s) copied. 1 file(s) copied. Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of %target% 12/21/2009 11:18 AM 9 me.dat-17333304.dat 12/21/2009 11:18 AM 9 me2.dat-17333304.dat 2 File(s) 18 bytes 0 Dir(s) 305,583,677,440 bytes free @BillRichardson: I thought you were banned. In any case if you noticed an error, why did you not simply fix it? Apparently anybody can be a critic, but if you're going to re-post code at least be accurate. I posted: if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l" ) else ( copy %source%\%%x "%target%\%%x") which I admit was in error. You posted: if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat" ) else ( copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat") which is also in error. The corrected code: Code: [Select]@echo off set source=F:\MPEGAV set target=C:\Documents and Settings\%username%\My Documents for /f %%x in ('dir /b %source%\*.dat') do ( for /f "tokens=1-4 delims=:." %%i in ("%time%") do ( if exist "%target%\%%x" (copy %source%\%%x "%target%\%%nx-%%i%%j%%k%%l.%%xx" ) else ( copy %source%\%%x "%target%\%%x") ) ) I always thought we were here to help out the OPs. Keep in mind BillRichardson these threads are not about you but about the Topic Starters. That's all I have to say...I refuse to get involved in a marathon thread with BillRichardson, et al. Quote from: Sidewinder on December 21, 2009, 05:23:21 PM @BillRichardson: _____________________________________ I respect your code and judgement more than anyone on this board. You code is much better than mine. I learn by running your code. The output always helps me. I thought the new file names should have a ".dat" at the end? I might have run the code incorrectly or had my folders set up wrong? I will erase or change the code as you suggest. Tell me exactly what to change. Is it wrong to show the output? I will do whatever you suggest. Thanks for your help several times in the past. Quote With an attitude like that, you'll never learn anything. Would have been better to post your unsuccessful attempt. It would have shown that you at least made an attempt for a solution. Well, I don't know if you're helpful for anyone previously, but not me... You just come and sounds like /I'm god, u're lazy boy, keep learning!/ Because there's people like you I wrote my question with those sentences above. I don't have to be a expert in command prompt console and I don't need to be someone like that. I'm here for get some help no matter how good/bad am I (in computer experience), people'd give a hand or not, it's their choice. You don't need to stay there and say that, it's too pointless thing after all~ 4rum just make for give people a chance to get help and it doesn't REQUIRE that much conditions (in rules, I don't see that I've to post all my attempt and etc....) Feel free ban nick or lock acc if u want. Don't worry, everybody is entitled to their opinion and you will not be banned for expressing yours. It's been said here and elsewhere "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime." Apparently you just want someone to hand you a fish. I must have been very tired last night, but post #6 (the corrected code) has an error. The corrected code (v2) is posted below. Take it for what it's worth. Code: [Select]@echo off set source=F:\MPEGAV set target=C:\Documents and Settings\%username%\My Documents for /f %%x in ('dir /b %source%\*.txt') do ( for /f "tokens=1-4 delims=:." %%i in ("%time%") do ( if exist "%target%\%%x" (copy %source%\%%x "%target%\%%~nx-%%i%%j%%k%%l%%~xx" ) else ( copy %source%\%%x "%target%\%%x") ) ) Quote I'm here for get some help no matter how good/bad am I (in computer experience), people'd give a hand or not, it's their choice I'll keep that in mind the next time you post. It will save me the aggravation of reading another one of your rants. Quote I'll keep that in mind the next time you post.OK, keep TALKING yourself about that. Don't start with fish and blah blah things... I'm working as a graphic artist and I can live without cmd, alright? I'm not a kid for you talk to me like that. And I don't need any ggdamn fish, just need a accurate and correct answer for my question, if it hurt your ego, then it's not my mistake. Thanks for nonetheless. You live as a IT supporter or programmer or whatever, me too. Then don't personally attach me about fish and etc...Quote from: nah on December 22, 2009, 07:48:15 AM OK, keep talking yourself about that.Nah, that wasn't an attack. He is just explaining that people who get taught how to do this understand it for a lifetime, no longer need help, and can even help others out (that's what happened to me), but people who only want the answer, they need help for the rest of their life. Quote from: nah on December 20, 2009, 06:56:40 AM I want make a batch file do this task. You were given at least 3 possible solutions. Which solution worked for you? |
|