Search

Please Subscribe

Like it? Share it!

Add to: JBookmarks Add to: Facebook Add to: Mr. Wong Add to: Buzka Add to: Windows Live Add to: Icio Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: Jumptags Add to: Upchuckr Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Diigo Add to: Technorati Add to: Newsvine Add to: Folkd Add to: Google

Get Your Gear at Amazon

Sponsors

HostMonster.com
HostMonster! Reliable and Affordable Web Hosting!
BlueHost.com
BlueHost, A Great Web Hosting solution.
Amazon.com - Hot Deals
Amazon.com! Check out computer related hot deals!
Get Clicky - Web Analytics
Cool Web Analytics Tool! Give it a try and let me know what you think
Upgrade Memory
Upgrade Your Ram! Simple tools to help find the correct memory stick at a great price.
Home Windows Settings How to Move files with a batch file
How to Move files with a batch file E-mail

The other day I was helping a friend with a reporting tool he was using. He mentioned that the application was really slow when loading data. The application he was running had log files that where populated into a directory. When the application would try and grab new data it had to go through all the files.

 

We wanted to keep the older files so if he ever needed to make change or apply a filters to the data it could be reloaded.  We decided to move the old files that where not needed to a new location. That way he could go back and grab the data but it would no effect the load time. We decided to move all files older then this year to a different directory. Instead of manually moving all the files we just created a batch file to do this in one click of a button. The application he used had the date the file was created in the name so this made things very easy. 

 

In this example I have setup two folders called original and new folder. We will move sample text files from the original folder to the new folder. In this example I will show you the code I used. I then will break it down and explain what each part does.

 

Let’s create a batch file to move these files

 

Example setup

 

Launch Notepad

Start > All Programs > Accessories > Notepad

 

Launch Notepad

Copy and paste the code below into the new document

 

move /-y "D:\example\original\*2007*.txt" "D:\example\New folder\"

pause

 

Your file should now look like this.(click on image see it larger)

Paste code into new document

 

we will need to save it as a batch file.

 

- Select File > Save as

- Select the location you would like to save the file

- Name the file and add “.bat” extension at the end (with out the “ “)

 

Save as .bat

You should now have a file that looks like this.

 

new bat file

 

 

Let’s now take a look at what the code does.

The fist part is defining what action is going to be executed. Since we are moving the files we are using move. We could also use copy if we just wanted to copy the files.

 

Move

The Next part is the /-Y. This is saying that you want to be prompted if there are duplicates. If you don’t care about files being overwritten in the new folder and don’t want to be prompted you can use /Y.

 

/-y (duplicate warning)

Dos help -windows explanation

 

-y in more depth

 

This part we are defining the file(s) we will be moving. So in this example this will be any file that has 2007 and .txt in its name. You will need to make sure you have the full path with “ “ around it.

 Where the File is located

This is where we will be moving the file to. Once again make sure you have the “ “ around the full path.

 

Where the File is going

 

The last part is to add a pause. Once the file executes you will be able to see if it completed successful as well as what files where moved.

 

Pause

Now to run the batch file you just double click on it.

 

Double click on your batch file

We should now see what files it has moved.

 

Sucess Full

This is an example of what it would look like if It didn’t run successful.

 

Failed

If you need to make changes to your batch file right click on it and select edit.

 

 
Please give us some feedback, let us know your thoughts about "How to Move files with a batch file"!

 

 

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
 


Another articles:


mixedperic.com
Feedback Form