Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Search file in subdirectory and create abd copy to another directory

Can someone help me with a CMD command to find a specific file in a subdir and if found it copy it to a mkdir folder.

Also would be great if it copy folder name it came from.

I have something like this now.. but it doesn't work correctly.


mkdir %temp%\test
dir where /r/s %appdata% *.txt
xcopy/S %appdata% *.txt %temp%\test

Some advice?


WOULD BE GREAT IF THIS CAN BE RUN HIDDEN WITHOUT THE CMD PROMP :)
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

You can do it with a vbscript file like this one ==> https://stackoverflow.com/questions/4482...ve#tab-top
That's kinda hard for me to understand how it works, can someone please give a example code?
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Jul 5, 2017 04:59 AM)YUGOBOSS Wrote:  That's kinda hard for me to understand how it works, can someone please give a example code?
So your aim is to find out all *.txt or a specific name text ???
(Jul 5, 2017 05:02 AM)Hackoo Wrote:  So your aim is to find out all *.txt or a specific name text ???

Could be any file, *.txt is just a example, but the most important part is the extention name ( .txt or .dll)
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Jul 5, 2017 05:03 AM)YUGOBOSS Wrote:  Could be any file, *.txt is just a example, but the most important part is the extention name ( .txt or .dll)
Here we go 😉
Code
@echo off
Set "Dest=%temp%\test"
MkDir %Dest% >nul 2>&1
CD /D %Appdata%
For /f "delims=" %%F in ('Dir /s /b *.dll *.txt') Do (
    @Copy /Y "%%F" "%Dest%"
)
Explorer "%Dest%"
😝
(Jul 5, 2017 05:15 AM)Hackoo Wrote:  Here we go 😉
Code
@echo off
Set "Dest=%temp%\test"
MkDir %Dest% >nul 2>&1
CD /D %Appdata%
For /f "delims=" %%F in ('Dir /s /b *.dll *.txt') Do (
    @Copy /Y "%%F" "%Dest%"
)
Explorer "%Dest%"
😝

I will try this out soon and let you know!
Thanks man!!


File is working thanks!
Only 1 problem, if there are multiply files with the same name it will only copy one or it will replace everything with the same, how can I prevent it from replacing files with the same name.

Like I have 4x test.txt inside the %appdata% It will only copy it once..

Also is there a way to copy the submap name from where it took the file?
Something like: subfolder test1\test.txt
subfolder test2\test.txt
subfolder test3\test.txt

Thanks for your help!
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Jul 5, 2017 05:49 AM)YUGOBOSS Wrote:  File is working thanks!
Only 1 problem, if there are multiply files with the same name it will only copy one or it will replace everything with the same, how can I prevent it from replacing files with the same name.

Like I have 4x test.txt inside the %appdata% It will only copy it once..

Also is there a way to copy the submap name from where it took the file?
Something like: subfolder test1\test.txt
subfolder test2\test.txt
subfolder test3\test.txt

Thanks for your help!
Here we go again ✌
Just give a try and tell me if this what you want or no ?
Code
@echo off
Title Copy *.txt *.dll files from "%AppData%"
REM If you want to add another extenstion just add in this variable Extensions with delimters ;
set "Extensions=txt;dll"
Set "Source=%Appdata%"
Set "target=%temp%\test"
MkDir %target% >nul 2>&1
For %%F in (%Extensions%) Do (
    Xcopy /SIFCY "%Source%\*.%%F" "%target%"
)
Explorer "%target%" & Exit
If you want another modification , just ask 👍


(Jul 5, 2017 03:56 AM)YUGOBOSS Wrote:  WOULD BE GREAT IF THIS CAN BE RUN HIDDEN WITHOUT THE CMD PROMP :)
If you want to run it in hidden mode means without the cmd prompt, you should save this file as a RunHiddenBatch.vbs and execute it 😉 ✌ 👍
Code
Option Explicit
Dim fso,ws,MyBatchFile,File
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
MyBatchFile = ws.ExpandEnvironmentStrings("%Temp%\MyBatchFile.bat")
Set File = fso.OpenTextFile(MyBatchFile,2,True)
'***************************************************************************************************
File.WriteLine "@echo off"
File.WriteLine "Title Copy *.txt *.dll files from ""%AppData%"" "
File.WriteLine "set ""Extensions=txt;dll"" "
File.WriteLine "Set ""Source=%Appdata%"" "
File.WriteLine "Set ""target=%temp%\test"" "
File.WriteLine "MkDir %target% >nul 2>&1"
File.WriteLine "For %%F in (%Extensions%) Do ( Xcopy /SIFCY ""%Source%\*.%%F"" ""%target%"" )"
Call Run(MyBatchFile,0)
'***************************************************************************************************
Function Run(StrCmd,Console)
    Dim ws,MyCmd,Result
    Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
    If Console = 0 Then
        MyCmd = "CMD /C " & StrCmd & " "
        Result = ws.run(MyCmd,Console,True)
        If Result = 0 Then
            'MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
'A value of 1 to show the MS-DOS console
    If Console = 1 Then
        MyCmd = "CMD /K " & StrCmd & " "
        Result = ws.run(MyCmd,Console,False)
        If Result = 0 Then
            'MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
    Run = Result
End Function
'****************************************************************************************************
(Jul 5, 2017 02:31 PM)Hackoo Wrote:  Here we go again ✌
Just give a try and tell me if this what you want or no ?
Code
@echo off
Title Copy *.txt *.dll files from "%AppData%"
REM If you want to add another extenstion just add in this variable Extensions with delimters ;
set "Extensions=txt;dll"
Set "Source=%Appdata%"
Set "target=%temp%\test"
MkDir %target% >nul 2>&1
For %%F in (%Extensions%) Do (
    Xcopy /SIFCY "%Source%\*.%%F" "%target%"
)
Explorer "%target%" & Exit
If you want another modification , just ask 👍


If you want to run it in hidden mode means without the cmd prompt, you should save this file as a RunHiddenBatch.vbs and execute it 😉 ✌ 👍
Code
Option Explicit
Dim fso,ws,MyBatchFile,File
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
MyBatchFile = ws.ExpandEnvironmentStrings("%Temp%\MyBatchFile.bat")
Set File = fso.OpenTextFile(MyBatchFile,2,True)
'***************************************************************************************************
File.WriteLine "@echo off"
File.WriteLine "Title Copy *.txt *.dll files from ""%AppData%"" "
File.WriteLine "set ""Extensions=txt;dll"" "
File.WriteLine "Set ""Source=%Appdata%"" "
File.WriteLine "Set ""target=%temp%\test"" "
File.WriteLine "MkDir %target% >nul 2>&1"
File.WriteLine "For %%F in (%Extensions%) Do ( Xcopy /SIFCY ""%Source%\*.%%F"" ""%target%"" )"
Call Run(MyBatchFile,0)
'***************************************************************************************************
Function Run(StrCmd,Console)
    Dim ws,MyCmd,Result
    Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
    If Console = 0 Then
        MyCmd = "CMD /C " & StrCmd & " "
        Result = ws.run(MyCmd,Console,True)
        If Result = 0 Then
            'MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
'A value of 1 to show the MS-DOS console
    If Console = 1 Then
        MyCmd = "CMD /K " & StrCmd & " "
        Result = ws.run(MyCmd,Console,False)
        If Result = 0 Then
            'MsgBox "Success"
        Else
            MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
        End If
    End If
    Run = Result
End Function
'****************************************************************************************************

Wow working great man!
Thank you so much.

One little question left.
I see you have made this option: File.WriteLine "set ""Extensions=txt;dll"" "

It will detect extensions, can I modify this to reconize name+extensions?
Now it will copy ALL dll and txt file, but if I only want test.dll and test.txt how can I do this?

Really appreciate your help men!

-------------------------------------------------------------------------------------------------------

Would be awesome if it could ZIP the files when copied succesfully, so all will be stored in 1 .zip or .rar file
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Jul 6, 2017 01:04 AM)YUGOBOSS Wrote:  It will detect extensions, can I modify this to reconize name+extensions
Now it will copy ALL dll and txt file, but if I only want test.dll and test.txt how can I do this?
Would be awesome if it could ZIP the files when copied succesfully, so all will be stored in 1 .zip or .rar file
Give a try for this batch file to catch test.txt and test.dll and i let you make a vbsfile for it !
Code
@echo off
Title Copy all test.txt and test.dll files from "%AppData%"
set "Files2Copy=test.txt;test.dll"
Set "Source=%Appdata%"
Set "target=%temp%\test"
MkDir %target% >nul 2>&1
For %%F in (%Files2Copy%) Do (
    Xcopy /SIFCY "%Source%\*%%F*" "%target%"
)
Explorer "%target%" & Exit
For your last request to zip or to rar a folder i will try to write you this code later ✌
(Jul 6, 2017 05:25 AM)Hackoo Wrote:  Give a try for this batch file to catch test.txt and test.dll and i let you make a vbsfile for it !
Code
@echo off
Title Copy all test.txt and test.dll files from "%AppData%"
set "Files2Copy=test.txt;test.dll"
Set "Source=%Appdata%"
Set "target=%temp%\test"
MkDir %target% >nul 2>&1
For %%F in (%Files2Copy%) Do (
    Xcopy /SIFCY "%Source%\*%%F*" "%target%"
)
Explorer "%target%" & Exit
For your last request to zip or to rar a folder i will try to write you this code later ✌

This one is working great! thank you very much.
Only this one is .bat yes? instead of vbs?

Would be great if the zip/rar could be possible :D
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Jul 6, 2017 06:23 AM)YUGOBOSS Wrote:  This one is working great! thank you very much.
Only this one is .bat yes? instead of vbs?

Would be great if the zip/rar could be possible :D
Did you like to zip this folder with a password protection or not ?
So, i will write a function in vbscript that let you choose if you want to protect it with a password or not ! 😉



EDIT :
Here we go again with a new vbscript :
Function added ==> Function Create_WinRar_Archive to create an archive rar file protected with a password 😉

Search_File_and_Winrar_it.vbs
Search_File_and_Winrar_it.vbs (Click to View)

Let me guess 😁
Your next question after zip a folder is to upload it via FTP ? Am i right ? 😝
(Jul 6, 2017 06:58 AM)Hackoo Wrote:  Did you like to zip this folder with a password protection or not ?
So, i will write a function in vbscript that let you choose if you want to protect it with a password or not ! 😉
Let me guess 😁
Your next question after zip a folder is to upload it via FTP ? Am i right ? 😝


Password protection would be great.
haha wow that idea about FTP is awesome, is it possible? 😝


Do you have skype maybe we can have a talk there.
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$

(Jul 6, 2017 08:16 AM)YUGOBOSS Wrote:  Password protection would be great.
haha wow that idea about FTP is awesome, is it possible? 😝

Check my last edit above 🎉 and tell me how it works on your side this new vbscript ✌
(Jul 6, 2017 08:40 AM)Hackoo Wrote:  Check my last edit above 🎉 and tell me how it works on your side this new vbscript ✌

Thanks again for your great help.
I have created .vbs file and run it the file copy is working perfectly but it does not pack .rar/.zip the files after.

Maybe I'm doing something wrong?


Oh wait! it does work but It drops the .rar file in %temp%
Password is working aswell!

Love you men :D
[Image: JTvy0Oo.png]
$̶1̶4̶9̶ -> 20$



Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Eternal BlueMay 14, 2022 04:02 PM 4 228 May 14, 2022 04:02 PM
Last Post: Sajuuk
[Python] by tcshDec 27, 2018 09:55 PM 9 340 Dec 27, 2018 09:55 PM
Last Post: FriendZone
[.NET] by Pesto50Jul 21, 2018 03:41 PM 2 150 Jul 21, 2018 03:41 PM
Last Post: Pesto50