7zip command line synthax using wildcard - command-line

Based on this source, the following should work for the 7zip command line tool:
7zG a -tzip "C:\20131024_archive.zip" "C:\archive" *20131024*
The goal is to zip all the files containing the date in the name. However, this is not working for me as it zips all the files without the date filter.
I've tried all sorts of variants without success. What am I doing wrong?

It turns out the date filter goes into the target filename like so:
7zG a -tzip "C:\20131024_archive.zip" "C:\archive\*20131024*"

Just use forfiles if your using windows 7. Type forfiles /? for more info. A think this will do what you want:
pushd C:\archive
forfiles /m "*20131024*" /c "7zG a -tzip C:\20131024_archive.zip #file"
I'm not sure this will work if the file name has spaces.

Related

How do I use Command Prompt to Find only execuatable files in drive C

I need to search for possible virus in drive c. I believe it is in .exe format.
Please advice on how to use command prompt to achieve this.
This will give you a list of exe files.
dir c:\*.exe /s >"%userprofile%\desktop\exelist.txt"
The above will not search all dirs/folders, try cd %userprofile%
and then
for /r /d %G in ('*.exe') DO echo Found Exe : %I

using #FILE in forfiles not working

I am trying to build a batch file that deletes all excel files older than 30 days. So far I have the command:
forfiles -p"N:\QC\ATR's" -s -m*.xls* -d-30 -c"CMD /C del /f /q #FILE"
The only problem seems to be the fact that #FILE has a space in the folder/file name so the del command cannot find the specified path. For example, looking at the echoes from the command it says
Could Not Find N:\QC\ATR's\'-5
When it should really be looking for the path
N:\QC\ATR's\-5 brightness study
See what I mean? Is there a way to tell the #FILE variable to be wrapped in quotes or something?
Thanks
You could try the following:
SET FILE = -5 brightness study
forfiles -p"N:\QC\ATR's" -s -m*.xls* -d-30 -c"CMD /C del /f /q %FILE%"
Check these sites for some assistance:
http://ss64.com/nt/path.html
http://www.windowsitpro.com/article/server-management/how-do-i-pass-parameters-to-a-batch-file-
I figured it out. I just added Hex coded qoutes around the file variable
forfiles -p"N:\QC\ATR's" -s -m*.xls* -d-30 -c"CMD /C del /f /q ^0x22#FILE^0x22"

How to delete files from a list?

I have a filesystem that uses a hash algorithm to organize files. I have used xcopy in the past to copy files to a different location by passing in a file that has a list of all the files and having it iterate through it. The script looks similar to the following:
for /f "delims=, tokens=1,2,3" %i in (D:\foo.csv)
do echo F | xcopy /i /d "Z:\%i\%j\%k" "Y:\%i\%j\%k" >> "D:\xcopy\Log.txt"
However, now I've run into a situation where in addition to copying the files that are provided in the foo.csv file, I want them to be deleted as well. I looked at the xcopy documentation and couldn't find anything. Is there someway I can accomplish this, even if I have to run another script to go through the same list of files and delete them after using xcopy?
Thanks!
You can use parenthesis to indicate multiple commands to be excecuted by the for operand:
for /f "delims=, tokens=1,2,3" %%i in (D:\foo.csv) do (
echo F | xcopy /i /d "Z:\%%i\%%j\%%k" "Y:\%%i\%%j\%%k" >> "D:\xcopy\Log.txt"
del /F "Z:\%%i\%%j\%%k"
)
I'm not familiar with Windows (I'm happily using Gnu/Linux since 1993), but perhaps you could add some command with variables like del %n somewhere (or replace xcopy with your own .bat file doing what you want)
From the look of it you can use move command instead of xcopy, since you're not using any extended features from xcopy. The '/d' is supposed to be used to only copy the files if they are newer, not sure how useful that is for your purpose since you want to delete them. Otherwise, move doesn't have many more options to speak of.
Another possible, and slightly more sophisticated, method is robocopy.
robocopy /MOVE /XO "Z:\%i\%j\%k" "Y:\%i\%j\%k"
The /MOVE would delete both folders and files after copying, and /XO flag excludes older files from being copied. robocopy is primarily available in newer operating systems (i.e. Not XP). You can check the above mentioned reference for more details.
Hope this helps. Although, just using del as previously mentioned should work fine also.

Having XCopy copy a file and not overwrite the previous one if it exists (without prompting)

I'm sending commands to a remote computer in order to have it copy a file.
I want the file to be copied, but not to overwrite the previous file with the same name (if it exists).
I also need the command to run without any prompts (xcopy likes to prompt whether the target name I've specified is file or directory, and it will also prompt about overwriting a file).
I have good results with xcopy /d.
It will copy NEWER files, and since we can assume that existing files have same time-stamp, you will copy only files that don't exist.
just in case anyone else finds this:
robocopy x:\sourcefolder Y:\destfolder /s /e /r:0 /z
much better than xcopy, even gives you a table at the end informing of any failed or skipped files. Doesn't prompt to not overwrite.
Well, there's a certain remedy! It has helped me with saving much of my effort and time on Win10 while writing a setup for our product demo.
Just try to use piping:
#ECHO N|COPY /-Y SourceFiles Destination
As an example I used this piece of code so that I would have a clean gentle quiet and safe copy!
#FOR /D %%F in ("FooPath") DO #(
#ECHO N|COPY /-Y ^"%%~npdxF\*.*^" ^"GooPath^" 3>NUL 2>NUL >NUL
)
where obviously FooPath is the source and GooPath is the destination.
Enjoy!
(main source: https://ss64.com/nt/copy.html)
Following command copy files and folder but not override file if already exist.
xcopy "*.*" "C:\test\" /s /y /d
No way to make it NOT overwrite as far as I know. but /Y will make it overwrite. and /I will get rid of the file/dict prompt. See xcopy /? for all options
You can also use the replace command. It has two modes: to add files that don't exist there or replace files that do exist. You want the previous mode:
replace <path1> <path2> /A
I had to copy AND rename files, so I got the prompt about creating a file or a directory.
This is the, rather "hackish" way I did it:
ECHO F | XCOPY /D "C:\install\dummy\dummy.pdf" "C:\Archive\fffc810e-f01a-47e8-a000-5903fc56f0ec.pdf"
XCOPY will use the "F" to indicate it should create the target as a file:
C:\install>ECHO F | XCOPY /D "C:\install\dummy\dummy.html" "C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html"
Does C:\Archive\aa77cd6e-1d19-4eb4-b2a8-3f8fe60daf00.html specify a file name or directory name on the target
(F = file, D = directory)? F
C:\install\dummy\dummy.html
1 File(s) copied
I've also verified this command leaves existing files alone. (You should too :-)

Making batch file for copying

Can anyone advise me please im using Windows XP Pro on C drive and need to be able to copy a file from one drive to another. This case original will have to be renamed and old file must be put on another Partiton which is on a Server Example K drive.
Alternately There is another option using Windows 7 on a another computer instead of Windows XP Pro. So any answers appreciated.
A quick look on my old DOS book that I saved just in case that I have to make batch files says COPY is the right command.
Syntax:
COPY DRIVE:FILENAME DRIVE:FILENAME
COPY THISFILE THATFILE
If your permissions are setup to allow copying, you can use "UNC" paths to copy files across servers and drives.
Like Noah said, check out ROBOCOPY or the slightly less featured XCOPY.
Enter copy /? or xcopy /? to find out the available options - if you append >file.txt you'll get them in a text file.
XCOPY Command:
xcopy c:\sourceDirectory\*.* d:\destinationDirectory\*.* /D /E /C /R /Y
ROBOCOPY Command:
robocopy c:\sourceDirectory\*.* d:\destinationDirectory\*.* /R:5 /W:3 /Z /XX /TEE
Either of these should work for you
Have you looked into robocopy?