I want to make a .exe that does basic windows functions in this particular order : search file / copy it / create new folder / paste said file into new folder.
I never programmed before, what language / program should i use ?
Thanks in advance






Blogs > Murlox |
Murlox
France1699 Posts
I want to make a .exe that does basic windows functions in this particular order : search file / copy it / create new folder / paste said file into new folder. I never programmed before, what language / program should i use ? Thanks in advance ![]() ![]() ![]() ![]() ![]() ![]() | ||
ghostWriter
United States3302 Posts
| ||
Murlox
France1699 Posts
| ||
Mastermind
Canada7096 Posts
| ||
Murlox
France1699 Posts
| ||
Cambium
United States16368 Posts
If you insist on having an executable, vb/vc++/C# can all do the trick. It's essentially a wrapper around a system call. Do you know the commands for these tasks? dir /s/b [file name] mkdir [new dir name] cp [dirs found in first step] [new dir name] There are probably specific libraries for these tasks as well, but I think sys calls will be the easiest. | ||
Murlox
France1699 Posts
| ||
illu
Canada2531 Posts
For something easy and accessible, go with Visual Basic. | ||
Murlox
France1699 Posts
dir /s/b [file1.txt] mkdir [F:/My Papers] cp [ ? ] [file1.txt] I am confused about what to put instead of the "?" | ||
Tehinf
United States192 Posts
| ||
b3h47pte
United States1317 Posts
On July 17 2009 10:19 Murlox wrote: Would this work : dir /s/b [file1.txt] mkdir [F:/My Papers] cp [ ? ] [file1.txt] I am confused about what to put instead of the "?" he's talking about a batch file. you put that into Notepad save it as "batch.bat" and run it and it'll do the stuff. http://www.computerhope.com/batch.htm That might help you a bit. If you still want to actually program something, if you're using .NET you can probably use teh Directory class: http://msdn.microsoft.com/en-us/library/system.io.directory.aspx | ||
AcrossFiveJulys
United States3612 Posts
On July 17 2009 10:19 Murlox wrote: Would this work : dir /s/b [file1.txt] mkdir [F:/My Papers] cp [ ? ] [file1.txt] I am confused about what to put instead of the "?" the format is like this: cp sourcepath destinationpath sourcepath/destinationpath refer to the location of the file and the name of the file appended to the end. so if you want to copy a file in C:\ called "file1" to F:\ and change the file name to "file2" you would do cp C:\file1 F:\file2 | ||
Murlox
France1699 Posts
Also, how do I input the path resulted of this search into the cp command ? cp [variable path] [F:\New Dir\] | ||
![]()
MasterOfChaos
Germany2896 Posts
create new folder <- What name? copy said file into new folder. | ||
Murlox
France1699 Posts
I want the .bat to search all drives for "file1.txt", whatever computer i use it on. Once it is located, i want the .bat to copy this file to a new folder, say NewFolder (Name is not important). That's all. Main problem is, when I test it, the "dir /s/b [file1.txt]" command fails at finding a file called "file1.txt" placed on my desktop ; Second problem is that I don't understand how to properly use the "cp" command, since I don't know how to write the first variable, ie. [located path of file1.txt after the search]. Btw, thank you guys for your help so far! | ||
yh8c4
108 Posts
@ECHO OFF 2>NUL md %2 FOR /F %%f IN ( '"dir \ /s /o /b %1"' ) DO copy /y %%f %2 > NUL you have to run the batch file with two parameters, 1 is the filename/search pattern which identifies the file you want, 2 is the path of the directory you want created. so, if you put that code in x.bat, you'd have to run: x asdf*.qwr c:\y, and if there is a file matching that pattern it will be put in c:\y (which will be created in every case). to break the code down a little bit - %1 and %2 refer to the first and second argument you typed when you ran the batch file - @ECHO OFF : turns off output (delete to see how %1 and %2 get substituted) - 2>NUL : suppress error message of md (which you will get if the directory already exists) - md : dos command for creating a directory - the FOR loop: for each item found in the paranthesis after IN the operation after DO is executed - dir \ /s /o /b %1 : this creates a list of all files matching the pattern you gave as first paramter. the \ after dir specifies that the search begins at the root directory. so, if you know that your file is somewhere beneath c:\asd\fgh\ use that instead \ - copy /y %%f %2 : copys all files matching the pattern to %2 (second parameter), the /y switch automatically overwrites existing files. the >NUL surpresses the copy output, if you want to have it delete it as far as i know you cant enumerate the valid drive letters from a batch file, so if you want to check multiple hard drives, so you might want to change the bat file to @ECHO OFF 2>NUL md %2 C: FOR /F %%f IN ( '"dir \ /s /o /b %1"' ) DO copy /y %%f %2 > NUL D: FOR /F %%f IN ( '"dir \ /s /o /b %1"' ) DO copy /y %%f %2 > NUL | ||
Murlox
France1699 Posts
Report, i used that: @ECHO OFF 2>NUL md %c:\test FOR /F %%f IN ( '"dir \ /s /o /b %moustique.exe"' ) DO copy /y %%f %c:\test I removed the >NUL since i don't want the original file to be deleted. This does make a folder c:\test, and replaces it with no warning on every use. However, this stops there, does not duplicate the file moustique.exe (which is located on my desktop) into the folder c:\test | ||
yh8c4
108 Posts
On July 18 2009 05:05 Murlox wrote: Report, i used that: @ECHO OFF 2>NUL md %c:\test FOR /F %%f IN ( '"dir \ /s /o /b %moustique.exe"' ) DO copy /y %%f %c:\test I removed the >NUL since i don't want the original file to be deleted. This does make a folder c:\test, and replaces it with no warning on every use. However, this stops there, does not duplicate the file moustique.exe (which is located on my desktop) into the folder c:\test try just these two lines to see all output: md c:\test FOR /F %%f IN ( '"dir \ /s /o /b moustique.exe"' ) DO copy %%f c:\test the variable names are %1 and %2, so if you want to replace them with constant values, you have to replace %1 and not just the 1. The >NUL stuff after the copy line actually just surpresses the output, but does not stop the auto overwrite. to remove that, you have to remove the /y switch. now, if a moustique.exe was found somewhere on your HD and copied it to c:\test and another moustique.exe is found somewhere else on your HD, you will be prompted to choose an action (i.e. you have to press y or n or sth) EDIT: btw, the copy command does indeed make a copy (it's not like in scifi movies where the original is gone after a copy, to achieve that effect you'd have to use "move" instead of "copy"). so, dont be afraid to use your source file ![]() | ||
Murlox
France1699 Posts
@ECHO OFF md c:\test copy moustique.exe c:\test However, the .bat HAS to be in the same directory as the file moustique.exe which is not what I want. Is there a better way to use the COPY command, that is to say not to have to specify the path of the source, only its name? @yh8c4 : mate, i don't understand your lines, and even after removing the % before 1 and 2 (which i did in the first place), it stills doesnt work to the end : it makes the directory, but doesn't copy the file in it. | ||
yh8c4
108 Posts
md C:\test FOR /F %%f IN ( '"dir C:\moustique.exe /s /b"' ) DO copy %%f C:\test | ||
Murlox
France1699 Posts
Your code does not work, neither do my old very simple "copy moustique.exe c:\test" anymore... and i rebooted. Wtf? | ||
yh8c4
108 Posts
it just takes ages to run if you have all your stuff in c:\ (since the copy only starts when dir has finally looked into every folder in C:\ for that file (no way to stop the search after the first found, afaik)). its a whole lot faster if you know that it's for example somewhere in C:\users (which is probably where your desktop folder is), so try md C:\test FOR /F %%f IN ( '"dir C:\Users\moustique.exe /s /b"' ) DO copy %%f C:\test | ||
Murlox
France1699 Posts
But even a very simple COPY command does not work anymore unless i specify the exact path, although it did work with no path at all minutes ago, so i suspect the .bat files to be somehow inneffective now? Thank you anyway, i will look why those .bat refuse to work any longer and will then try your code. Edit : I mean, even md c:\test doesn't work! | ||
yh8c4
108 Posts
| ||
Murlox
France1699 Posts
Ok, so : md C:\test FOR /F %%f IN ( '"dir C:\Users\moustique.exe /s /b"' ) DO copy %%f C:\test does create c:\test, but does not copy moustique.exe in it for me. On the other hand, md c:\test copy moustique.exe c:\test does create c:\test and copies moustique.exe in it Problem here, the .bat has to be in the same repertory as moustique.exe to work | ||
yh8c4
108 Posts
| ||
Murlox
France1699 Posts
Edit : even with md C:\test FOR /F %%f IN ( '"dir C:\Documents and Settings\Murlox\Bureau\moustique.exe /s /b"' ) DO copy %%f C:\test It still does not do the trick. Won't copy. Moreover, this is not really the direction i want to go, since what I really want is not to input any path at all, (.bat should find the file itself) | ||
yh8c4
108 Posts
| ||
Murlox
France1699 Posts
| ||
Adeny
Norway1233 Posts
| ||
Murlox
France1699 Posts
We are right on the point mate :-) I think basic dos commands can do my job, well i hope so. If i manage to get this DIR or COPY or XCOPY command to look for my file without feeding them the path of it... @yh8c4 : /b after DIR is for clarification (no summary) /s after DIR is to display files in specified directory and all subdirectories. I think this does not mean every subdirectories of the drive though, but just the subdirectories of specified directory... Which is not enough in my case ;7 May be DIR is not the proper command? dir \ moustique.exe /s finds it ! | ||
yh8c4
108 Posts
md C:\test FOR /F "delims=" %%f IN ( '"\moustique.exe /b /s"' ) DO copy "%%f" C:\test faster version with a small hint to your desktop... md C:\test FOR /F "delims=" %%f IN ( '"C:\"Documents and Settings"\moustique.exe /b /s"' ) DO copy "%%f" C:\test better copy-paste, this has some more "s... | ||
Murlox
France1699 Posts
Neither your versions work... | ||
yh8c4
108 Posts
On July 18 2009 08:46 Murlox wrote: Hei da, We are right on the point mate :-) I think basic dos commands can do my job, well i hope so. If i manage to get this DIR or COPY or XCOPY command to look for my file without feeding them the path of it... @yh8c4 : As I understand it, /b after DIR is for clarification (no summary) /s after DIR is to display files in specified directory and all subdirectories. I think this does not mean every subdirectories of the drive though, but just the subdirectories of specified directory... Which is not enough in my case ;7 May be DIR is not the proper command? /b outputs the complete path to the file + filename and no this date, size etc crap, we just need the path + name to feed it to the copy command /s if the specified directory is \ then /s means checking each and every directory on that drive the dir command isnt optimal for your problem (since you probably want the search to end once the file has been located), but there's nothing which gets the job done (that is providing the source paramter for the copy command) | ||
Murlox
France1699 Posts
Because DIR \ moustique.exe /s finds the file ; how can use this result as a source for COPY ? | ||
yh8c4
108 Posts
![]() On July 18 2009 09:06 Murlox wrote: Btw, how do you use the result provided by the DIR command with the COPY command ? Because DIR \ moustique.exe /s finds the file ; how can use this result as a source for COPY ? thats what the FOR loop does the stuff in the parantheses after IN is a set of dir results. you basically say: let %%f be a member of this set, then for each member in that set do copy %%f c:\test. you know what i mean? for each item in the IN ( ... ) set copy is called once, and %%f gets substituted with that item. | ||
Murlox
France1699 Posts
And FOR loops this whole system. Am i getting it right? | ||
Murlox
France1699 Posts
Thank you very much for you help yh8c4, was a pleasure ![]() | ||
yh8c4
108 Posts
![]() i put some files in c:\tmp\x (printed with /b /s) then i print out the content of x.bat (with the type command) then i run x.bat, and you can see that copy is run 4 times, because the call for dir *.txt /b /s yielded 4 results, which are the contents inside the IN ( ). each time copy is run, it is run with a different source parameter, because each time the %%f gets substituted with a different item from the IN ( ) set. i'm 100% sure, that md C:\test FOR /F "delims=" %%f IN ( '"\moustique.exe /b /s"' ) DO copy "%%f" C:\test works, just run it and make a screenshot ![]() | ||
yh8c4
108 Posts
md C:\test FOR /F "delims=" %%f IN ( '"dir \moustique.exe /b /s"' ) DO copy "%%f" C:\test | ||
Murlox
France1699 Posts
I will look at your screenshot more in depth this w-e. Thanks again so much for you time and experience dude! ![]() (its crazy fast too!!!) Edit : I'm wrong, it is more than fast, it is INSTANT. | ||
yh8c4
108 Posts
![]() here's some more detailed info: http://www.robvanderwoude.com/batchfiles.php | ||
Cambium
United States16368 Posts
glad you resolved your problem | ||
Cambium
United States16368 Posts
dir /sb *.* | xargs -n1 cp --target-directory=.\temp2 | ||
| ||
Kung Fu Cup
Kung Fu Cup #8 SC EVO Complete
WardiTV Spring Champion…
Group Stage 2 - Group A
Creator vs ByuNLIVE!
[ Submit Event ] |
![]() StarCraft 2 StarCraft: Brood War Britney Stormgate![]() ![]() Calm ![]() Rain ![]() Shuttle ![]() Jaedong ![]() Mini ![]() Stork ![]() Snow ![]() ZerO ![]() ggaemo ![]() [ Show more ] Dota 2 Super Smash Bros Heroes of the Storm Other Games singsing4172 Beastyqt1035 hiko746 Lowko680 XBOCT425 DeMusliM357 Fuzer ![]() Liquid`VortiX144 XaKoH ![]() KnowMe76 QueenE55 ZerO(Twitch)20 Organizations StarCraft 2 StarCraft: Brood War StarCraft 2 StarCraft: Brood War
StarCraft 2 • StrangeGG StarCraft: Brood War![]() • IndyKCrew ![]() • AfreecaTV YouTube • sooper7s • Migwel ![]() • intothetv ![]() • LaughNgamezSOOP • Kozan Dota 2 League of Legends Other Games |
Replay Cast
Rex Madness
MaxPax vs Ryung
ByuN vs Rogue
Replay Cast
WardiTV Spring Champion…
herO vs SKillous
Classic vs Bunny
Korean StarCraft League
SOOP
Classic vs Rogue
CranKy Ducklings
WardiTV Spring Champion…
Cure vs TriGGeR
MaxPax vs Dark
Replay Cast
Afreeca Starleague
Rain vs Action
Bisu vs Queen
[ Show More ] Wardi Open
Afreeca Starleague
Snow vs Rush
hero vs Mini
Online Event
The PondCast
WardiTV Spring Champion…
Rogue vs Zoun
Clem vs ShoWTimE
|
|