Jump to content

I've got some files scattered around my 'My Documents' folder, which I would like to gather regularly, once every three days. For the sake of automating the process, I look at CMD (Batch-Scripting) for an answer.

 

EDIT : I posted a similar topic in another sub-forum - I don't think it was the right on though... which I why I created a similar topic!

 

Thanks!!!

Nothing to see here ;)

Link to comment
https://linustechtips.com/topic/550925-gather-scattered-files-using-cmd/
Share on other sites

Link to post
Share on other sites

are they specific ducuments or and what do you plan on doing with them? you could do something like copying the ones that fit some variable or file type into a folder and then deleting the original or something, thats my best idea, im pretty familiar with batch but i have never done something like this, might give it a shot too :)

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

20 minutes ago, Bananasplit_00 said:

are they specific ducuments or and what do you plan on doing with them? you could do something like copying the ones that fit some variable or file type into a folder and then deleting the original or something, thats my best idea, im pretty familiar with batch but i have never done something like this, might give it a shot too :)

They are all .exe (console apps) files I compile using Visual Studio 2015, and I want to copy it all in a folder, on my desktop, for instantaneous access. And I also learn the intricacies of batch-files...

Nothing to see here ;)

Link to post
Share on other sites

well i have gotten a bit on the way with my wack at it, i am at the moment just making a list of all the .exe files and putting them in a .txt document, now i just need to figure out how to copy all of them to a folder xD

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

ok im done, here you go, here is the code:

 

Quote

@echo off
setlocal enabledelayedexpansion
for /r %%i in (*.exe) do (
    copy %%~i C:\Users\Admin\Desktop\target
)
endlocal

 

just change the copy path and you should be good to go :D, put it in the documents folder and run it, it then copys the .exe files to the specified folder, in my case "target" placed on my desktop. you can change out the copy to move if you  want and  it should be just fine with that too, then it will move the files to the folder insetad of copying them. hope this was usefull to you, i sure had a LOAD of fun making this so i dont really mind. just one thing, if the file name has a space in the name it wont copy it, it will just throw an error and then just not care about it and it will keep going. hope this was of some help or that you learned something :)

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

On 2/19/2016 at 4:47 AM, Bananasplit_00 said:

ok im done, here you go, here is the code:

 

just change the copy path and you should be good to go :D, put it in the documents folder and run it, it then copys the .exe files to the specified folder, in my case "target" placed on my desktop. you can change out the copy to move if you  want and  it should be just fine with that too, then it will move the files to the folder insetad of copying them. hope this was usefull to you, i sure had a LOAD of fun making this so i dont really mind. just one thing, if the file name has a space in the name it wont copy it, it will just throw an error and then just not care about it and it will keep going. hope this was of some help or that you learned something :)

Man! Thank you very much for all the help.

Nothing to see here ;)

Link to post
Share on other sites

55 minutes ago, anandgeforce said:

Man! Thank you very much for all the help.

glad to help, was really fun trying to make it :)

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

29 minutes ago, Bananasplit_00 said:

glad to help, was really fun trying to make it :)

BTW, how do you specify the source folder? Or does it just start scouring the directory it is run from?

 

I repeat, thanks a lot, a ton, whatever, I'm truly happy that I received a solution to my ever-existing problem!

Nothing to see here ;)

Link to post
Share on other sites

1 hour ago, anandgeforce said:

BTW, how do you specify the source folder? Or does it just start scouring the directory it is run from?

 

I repeat, thanks a lot, a ton, whatever, I'm truly happy that I received a solution to my ever-existing problem!

just put it in the folder you want to search through, so you would just put it in the documents folder and then point it at a folder somewhere on the desktop or something :), you can always just have a shortcut on the desktop for convenience so you dont need to go into the documents folder to run it

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

27 minutes ago, Bananasplit_00 said:

just put it in the folder you want to search through, so you would just put it in the documents folder and then point it at a folder somewhere on the desktop or something :), you can always just have a shortcut on the desktop for convenience so you dont need to go into the documents folder to run it

Alright - I'll try it right now (BTW using Windows 7 Ultimate) hope it works...

 

Uh... it says "The system cannot find the file specified".

 

I shall replicate my directory structure :-

 

C:\Users 

     |     

     --> Anand

               |

               --> My Documents

                               |

                               -->Visual Studio 2015

                                               |

                                               --> Projects

 

In the Projects folder, there are many folders, each containing an exe file within a sub-folder, and here is also where I placed the .bat file (it is .bat right???) that you generously gave.

 

And hey, thanks again for your effort and time!

Nothing to see here ;)

Link to post
Share on other sites

21 minutes ago, anandgeforce said:

Alright - I'll try it right now (BTW using Windows 7 Ultimate) hope it works...

 

Uh... it says "The system cannot find the file specified".

 

I shall replicate my directory structure :-

 

C:\Users 

     |     

     --> Anand

               |

               --> My Documents

                               |

                               -->Visual Studio 2015

                                               |

                                               --> Projects

 

In the Projects folder, there are many folders, each containing an exe file within a sub-folder, and here is also where I placed the .bat file (it is .bat right???) that you generously gave.

 

And hey, thanks again for your effort and time!

and what is your target folder? if you didnt change that there migtht be a problem

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

50 minutes ago, Bananasplit_00 said:

and what is your target folder? if you didnt change that there migtht be a problem

Target folder : "C:\Users\Anand\Desktop\Apps". I'd already changed that...

 

And does it search the sub-directories too? That's where the executables are.

Nothing to see here ;)

Link to post
Share on other sites

1 hour ago, anandgeforce said:

Target folder : "C:\Users\Anand\Desktop\Apps". I'd already changed that...

 

And does it search the sub-directories too? That's where the executables are.

it should do that, il test that right now just to be sure :)

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

Ok it does 1 level of sub directories, thought it would go deeper :/ well thats what it does right now, if you need it to go deeper i might look into it but i cant say it will find a solution to that

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

15 hours ago, Bananasplit_00 said:

Ok it does 1 level of sub directories, thought it would go deeper :/ well thats what it does right now, if you need it to go deeper i might look into it but i cant say it will find a solution to that

I just don't know how to thank you - but I'm really concerned, are you fine with helping me to this extent? You've already put in so much of an effort for me...:)

Nothing to see here ;)

Link to post
Share on other sites

15 hours ago, Bananasplit_00 said:

Ok it does 1 level of sub directories, thought it would go deeper :/ well thats what it does right now, if you need it to go deeper i might look into it but i cant say it will find a solution to that

Every executable is in the following general path : 

 

Visual Studio 2015\Projects\<Project Name>\Release<or>Debug\blah_blah.exe

 

You see, there are 2 sub-folders, which I have to cross to reach the executables...

Nothing to see here ;)

Link to post
Share on other sites

Using xcopy you can do this in 1 line specifying the source & destination folders as well as whether to include subfolders, all as arguments. For more info, see: https://technet.microsoft.com/en-us/library/cc771254.aspx & you're going to want to specify the source as DirectoryPathGoesHere\*.exe in order for all your exe files to be picked up.

 

If you want this run every 3 days, look at the inbuilt Windows task scheduler. Hitting the new menu entry will launch a wizard type of dialog allowing you to, I believe, both choose when you want this run & allowing you to enter the xcopy command with all the arguments there.

Link to post
Share on other sites

4 hours ago, alex_read said:

Using xcopy you can do this in 1 line specifying the source & destination folders as well as whether to include subfolders, all as arguments. For more info, see: https://technet.microsoft.com/en-us/library/cc771254.aspx & you're going to want to specify the source as DirectoryPathGoesHere\*.exe in order for all your exe files to be picked up.

 

If you want this run every 3 days, look at the inbuilt Windows task scheduler. Hitting the new menu entry will launch a wizard type of dialog allowing you to, I believe, both choose when you want this run & allowing you to enter the xcopy command with all the arguments there.

cool dude :) thats nice

 

7 hours ago, anandgeforce said:

Every executable is in the following general path : 

 

Visual Studio 2015\Projects\<Project Name>\Release<or>Debug\blah_blah.exe

 

You see, there are 2 sub-folders, which I have to cross to reach the executables...

well now im having a LOAD of problems with it, now it wont pick up the files it used to and a load of other things :/ il tell you if i get something working but it only seems to be going one subfolder deep right now still. il try working something out but take a look at this other dudes thing, seems like something easyer xD

I spent $2500 on building my PC and all i do with it is play no games atm & watch anime at 1080p(finally) watch YT and write essays...  nothing, it just sits there collecting dust...

Builds:

The Toaster Project! Northern Bee!

 

The original LAN PC build log! (Old, dead and replaced by The Toaster Project & 5.0)

Spoiler

"Here is some advice that might have gotten lost somewhere along the way in your life. 

 

#1. Treat others as you would like to be treated.

#2. It's best to keep your mouth shut; and appear to be stupid, rather than open it and remove all doubt.

#3. There is nothing "wrong" with being wrong. Learning from a mistake can be more valuable than not making one in the first place.

 

Follow these simple rules in life, and I promise you, things magically get easier. " - MageTank 31-10-2016

 

 

Link to post
Share on other sites

9 hours ago, Bananasplit_00 said:

cool dude :) thats nice

 

well now im having a LOAD of problems with it, now it wont pick up the files it used to and a load of other things :/ il tell you if i get something working but it only seems to be going one subfolder deep right now still. il try working something out but take a look at this other dudes thing, seems like something easyer xD

I'll try xcopy method... Thanks again!

Nothing to see here ;)

Link to post
Share on other sites

13 hours ago, alex_read said:

Using xcopy you can do this in 1 line specifying the source & destination folders as well as whether to include subfolders, all as arguments. For more info, see: https://technet.microsoft.com/en-us/library/cc771254.aspx & you're going to want to specify the source as DirectoryPathGoesHere\*.exe in order for all your exe files to be picked up.

 

If you want this run every 3 days, look at the inbuilt Windows task scheduler. Hitting the new menu entry will launch a wizard type of dialog allowing you to, I believe, both choose when you want this run & allowing you to enter the xcopy command with all the arguments there.

 

Please have a look at my directory structure - you'll have to cross 2 levels of sub-folders to even reach the executables... each has its own set of the 2 sub-folders, so have you tried it? Is it possible?

 

Thanks!

17 hours ago, anandgeforce said:

Every executable is in the following general path : 

 

C:\Users\Anand\Visual Studio 2015\Projects\<Project Name>\Release<or>Debug\blah_blah.exe

 

You see, there are 2 sub-folders, which I have to cross to reach the executables...

 

Nothing to see here ;)

Link to post
Share on other sites

I've just double checked and yes, the subdirectory scan which xcopy uses is recursive alright - i.e. it'll pickup all subfolders no matter how deep the nesting is, under the directory you specify.

 

One reason I like to help assist in forums like this (on top of feeling great I can help others) is that you get to learn so much at the same time too. I've just now found the xcopy command, whilst still available in Windows, has had some memory issues with scanning huge amounts of files & is deprecated. The new command which I wasn't aware of earlier myself, is ROBOCOPY. This will work in a similar way & also perform your recursive subdirectory scan.

 

@BananaSplit_00: Impressive first try at the script & with a bit more work that could have been made recursive & would have worked too. I just wanted to give some friendly advice that if you're interested & excited with the batch coding side of things for the future, it's now pretty much been replaced with the more powerful "powershell" commands in Windows & you might want to take a look at that line. :c)

 

Link to post
Share on other sites

3 hours ago, alex_read said:

I've just double checked and yes, the subdirectory scan which xcopy uses is recursive alright - i.e. it'll pickup all subfolders no matter how deep the nesting is, under the directory you specify.

 

One reason I like to help assist in forums like this (on top of feeling great I can help others) is that you get to learn so much at the same time too. I've just now found the xcopy command, whilst still available in Windows, has had some memory issues with scanning huge amounts of files & is deprecated. The new command which I wasn't aware of earlier myself, is ROBOCOPY. This will work in a similar way & also perform your recursive subdirectory scan.

 

@BananaSplit_00: Impressive first try at the script & with a bit more work that could have been made recursive & would have worked too. I just wanted to give some friendly advice that if you're interested & excited with the batch coding side of things for the future, it's now pretty much been replaced with the more powerful "powershell" commands in Windows & you might want to take a look at that line. :c)

 

I'm currently using ROBOCOPY, and I'm able to gather all the executables, but with them, two full levels of subfolders! Yes, I'm unable to copy just the files to the destination...

 

And I definitely agree with you on the part where you say that we ourselves learn many things while trying to help/teach another...

Nothing to see here ;)

Link to post
Share on other sites

I see. I've just tried xcopy and robocopy myself and understand better now.

 

PowerShell has a copy-Item method but it doesn't behave as it's name implies with the -recursive switch (either that or there's a massive glaring bug). Thankfully, TheMadTechnician pointed this out here http://stackoverflow.com/questions/25817034/recursively-copy-a-set-of-files-from-one-directory-to-another-in-powershell so thumbs up to him. I've modified his code a little and this should sort you out. Change the source & destination paths here & save the file with a .ps1 extension. Open PowerShell from the Windows run dialog or search then type the filename in & hit enter:

 

$Source = 'C:\SourceDirectory'
$Files = '*.exe'
$Dest = 'C:\DestinationDirectory'
Get-ChildItem $Source -Filter $Files -Recurse | ForEach{
    $Path = ($_.DirectoryName + "\") -Replace [Regex]::Escape($Source), $Dest
    If(!(Test-Path $Path)){
        Copy-Item $_.FullName -Destination $Dest -Force
    }
}



			
		
Link to post
Share on other sites

23 hours ago, alex_read said:

I see. I've just tried xcopy and robocopy myself and understand better now.

 

PowerShell has a copy-Item method but it doesn't behave as it's name implies with the -recursive switch (either that or there's a massive glaring bug). Thankfully, TheMadTechnician pointed this out here http://stackoverflow.com/questions/25817034/recursively-copy-a-set-of-files-from-one-directory-to-another-in-powershell so thumbs up to him. I've modified his code a little and this should sort you out. Change the source & destination paths here & save the file with a .ps1 extension. Open PowerShell from the Windows run dialog or search then type the filename in & hit enter:

 

 


$Source = 'C:\SourceDirectory'

	$Files = '*.exe'

	$Dest = 'C:\DestinationDirectory'

	Get-ChildItem $Source -Filter $Files -Recurse | ForEach{

	    $Path = ($_.DirectoryName + "\") -Replace [Regex]::Escape($Source), $Dest

	    If(!(Test-Path $Path)){

	        Copy-Item $_.FullName -Destination $Dest -Force

	    }

	}


 

I'm not on near my PC right now, but I'll try this as fast as possible. Thanks a ton!!!

 

BTW, Is it possible to just launch it using a shortcut? Going into Powershell everytime is tedious business - as I want to automate it using Scheduled Tasks, to run everyday.

Nothing to see here ;)

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×