View previous topic :: View next topic |
Author |
Message |
asianking Expert Cheater
Reputation: 0
Joined: 25 Jun 2008 Posts: 107
|
Posted: Wed Feb 16, 2011 4:05 pm Post subject: Need help with batch commands! |
|
|
Is there a simpler way to knock down these codes into one line only?
Code: |
IF %M%==5 xcopy /y "C:\project\*.accdb" "E:\Projects"
IF %M%==5 xcopy /y "C:\project\*.doc" "E:\Projects"
IF %M%==5 xcopy /y "C:\project\*.xlsx" "E:\Projects" |
I tried using the & character, but still not working. What this batch code does is if I press 5, it will copy overwrite or just copy those extension type of files into my projects folder E drive. Isn't there a way I can just for example type:
Code: |
IF %M%==5 xcopy /y "C:\Project\*.accdb&*.doc&*.slsx" "E:\Projects"
|
----------
If you ask why I didn't do the full folder copy to the E drive; It's because I have lots of other different files format types in there that I don't want it copy. Those are the main ones that I only need.
_________________
|
|
Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Wed Feb 16, 2011 4:34 pm Post subject: |
|
|
Bruteforce the file types.
|
|
Back to top |
|
 |
asianking Expert Cheater
Reputation: 0
Joined: 25 Jun 2008 Posts: 107
|
Posted: Wed Feb 16, 2011 5:34 pm Post subject: |
|
|
example pls...
_________________
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Feb 16, 2011 7:00 pm Post subject: |
|
|
Code: |
set FILE_doc=* .doc
set FILE_accdb=* .accdb
set FILE_xlsx=* .xlsx
FOR /F "tokens=2* delims=_=" %A IN ('SET FILE_') DO xcopy c:\projects\%B e:\projects\
|
Try that.
http://www.robvanderwoude.com/battech_array.php
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
asianking Expert Cheater
Reputation: 0
Joined: 25 Jun 2008 Posts: 107
|
Posted: Thu Feb 17, 2011 9:24 am Post subject: |
|
|
works, but i'm not lookin for extra codes. I'm looking to short codes out to one line. I'm assuming there isn't a way then.
With that code, I could just go with my first code which is shorter. Thanks anyway, but is there another suggestion?
_________________
|
|
Back to top |
|
 |
Fantasy I post too much
Reputation: 13
Joined: 29 Jul 2007 Posts: 3113
|
Posted: Thu Feb 17, 2011 10:18 am Post subject: |
|
|
Jorg hi wrote: | Bruteforce the file types. |
What? 0o
- Also, why is it needed to be a single line?
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu Feb 17, 2011 11:20 am Post subject: |
|
|
Why is it so important to have it all on one line?
Anyways, the code I gave needs slight modification.
Now for the ultra-mega-super-one liner
Code: |
IF %M%==5 FOR /r C:\Project\ %%A IN ( *.accdb *.doc *.slsx ) DO xcopy "%%A" E:\Projects\ /y /s /e
|
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
asianking Expert Cheater
Reputation: 0
Joined: 25 Jun 2008 Posts: 107
|
Posted: Fri Feb 18, 2011 7:31 am Post subject: |
|
|
Will give it a try when I'm at work. Not important; just want it to shorten out most batch commands. Save disk space
_________________
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Fri Feb 18, 2011 9:22 am Post subject: |
|
|
OMG I hope you are joking about disk space. LMFAO
It will work as long as you run the batch from the same dir as your files, otherwise if you would like to run it from anywhere you need to change xcopy "%%A" to xcopy "C:\Projects\%%A"
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
asianking Expert Cheater
Reputation: 0
Joined: 25 Jun 2008 Posts: 107
|
Posted: Fri Feb 18, 2011 12:45 pm Post subject: |
|
|
for some reason it doesn't work. When I press 5, it automatic close the prompt right away. I check the folder and nothing was copy. Any idea why?
Here's the partial code I input and tell me what's wrong?
Code: |
SET /P M=Type 1, 2, 3, 4, 5, or 6, then press ENTER:
IF %M%==1 xcopy /y /p "C:\project\Desk*" "E:\Projects"
IF %M%==2 xcopy /y /p "C:\project\Serv*" "E:\Projects"
IF %M%==3 xcopy /y /p "C:\project\Tuto*" "E:\Projects"
IF %M%==4 xcopy /y /p "C:\project\PCas*" "E:\Projects"
IF %M%==5 FOR /r C:\projects %%A IN (*.accdb *.doc *.slsx) DO xcopy "%%A" E:\projects /y /s /e
IF %M%==6 GOTO EOF
|
_________________
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Fri Feb 18, 2011 2:23 pm Post subject: |
|
|
Just tested your code only changed the output dir to C:\test my E:\ is a cd burner, and added pause at the end to have it wait so I could see state, worked perfectly.
Code: |
SET /P M=Type 1, 2, 3, 4, 5, or 6, then press ENTER:
IF %M%==1 xcopy /y /p "C:\project\Desk*" "E:\Projects"
IF %M%==2 xcopy /y /p "C:\project\Serv*" "E:\Projects"
IF %M%==3 xcopy /y /p "C:\project\Tuto*" "E:\Projects"
IF %M%==4 xcopy /y /p "C:\project\PCas*" "E:\Projects"
IF %M%==5 FOR /r C:\projects %%A IN (*.accdb *.doc *.slsx) DO xcopy "%%A" E:\projects /y /s /e
IF %M%==6 GOTO EOF
GOTO START
PAUSE
|
Add that pause there, take a look at the error. Also as I mentioned before as it is currently written it will only copy as long as it is run from the directory where the files are. You will need to specify the directory after the xcopy command.
xcopy "%%A" needs to be xcopy "c:\projects\%%A"
If you intend to run it from anywhere on your computer.
Also changed the code a bit to close when I wanted it to.
Code: |
:START
SET /P M=Type 1, 2, 3, 4, 5, or 6, then press ENTER:
IF %M%==1 xcopy /y /p "C:\project\Desk*" "E:\Projects"
IF %M%==2 xcopy /y /p "C:\project\Serv*" "E:\Projects"
IF %M%==3 xcopy /y /p "C:\project\Tuto*" "E:\Projects"
IF %M%==4 xcopy /y /p "C:\project\PCas*" "E:\Projects"
IF %M%==5 FOR /r C:\projects %%A IN (*.accdb *.doc *.slsx) DO xcopy "%%A" E:\projects /y /s /e
IF %M%==6 GOTO EOF
:EOF
|
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
|