7z Command Line Extract code does not extract files into specified folder - 7zip

I have written a command line extract code :
7z x C:\\Users\\Anuj\\Desktop\\th.7z -p123 -oC:\\Program Files\\OpenVPN *.* -r"
Here the given Output path is :
C:\\Program Files\\OpenVPN *.* -r"
However The zip file gets extracted to :
C:\Program\
I have identified the problem too, the problem is the code cannot take spaces in file folder.if the file output is changed to C:\\ProgramFiles\\OpenVpn
It works. BUt if the path is C:\\Program Files\\OpenVPN It doesnt

I was getting the ACCESS DENIED error for the code below:
declare #unzip varchar(500)
set #unzip='"C:\Program Files\7-Zip\7z.exe" e D:\Documents\test_compress.zip -oD:\Documents\test_compress'
exec master..xp_cmdshell #unzip
All I had to do was allow the MSSQL application the FULL ACCESS control. To do that first find the application name :
exec master..xp_cmdshell 'whoami' -- nt service\mssqlserver
Now go to D:\Documents - Right Click the Documents folder - Click "Properties - Go to "Security" tab -- If MSSQLSERVER is not listed then Click "Edit" and then click "Add" -- Add "NT SERVICE\MSSQLSERVER" and now check the option "Full Control" Allow

From: http://7zip.bugaco.com/7zip/MANUAL/syntax.htm
Wildcards or filenames with spaces must be quoted:
"Dir\Program files\*"
Dir\"Program files"\*
Hope this helps.

Related

Windows 10 create a softlink to a file

On Windows 10 I am trying to create a soft link to a file through command prompt opened as an Administrator.
mklink "E:\Folder A\Folder B" "E:\Folder A\Folder C\bibliography.bib"
...where I want to create a soft link to bibliography.bib file into a folder B.
This throws me an error Access denied
What could be the reason?
Had to modify my command to
mklink "E:\Folder A\Folder B\bibliography.bib" "E:\Folder A\Folder C\bibliography.bib"
first of all we can create symbolic link from empty directory to file or visa versa - from empty file to directory via FSCTL_SET_REPARSE_POINT - this is legal and will be work. and we can work with target file (or directory) through this symlink. say in case target is file - we can open and read it as file. but any file browser will be incorrect work with such symlink, because it will be use source file attribute FILE_ATTRIBUTE_DIRECTORY - as result try work with file like with directory or visa versa. because this exist sense use only file -> file or directory -> directory symbolic links (the src and target have the same FILE_ATTRIBUTE_DIRECTORY attribute - both have or not have)
also the mklink assume that symbolic link to be created file - yet not exist. internally it use NtCreateFile with FILE_CREATE disposition. as result we got error, if file already exist. if directory already exist and in call NtCreateFile we not use option FILE_DIRECTORY_FILE (mklink use this option when we use /D switch) - we got STATUS_FILE_IS_A_DIRECTORY error. (The file that was specified as a target is a directory and the caller specified that it could be anything but a directory.). but mklink before display error message, first convert it to win32 error code, and it converted to.. ERROR_ACCESS_DENIED. as result we and view Access denied message, despite the error have nothing common with access denied
if we want create symlink to file via mklink, we need select yet not existing file name(path) as symbolic link to be created

Windows batch - concatenate multiple text files into one

I need to create a script, which concatenates multiple text files into one.
I know it's simple to use
type *.txt > merged.txt
But the requirement is to "concatenate files from same day into file day_YYYY-DD-MM.txt" I am a Linux user and Windows batch is hell for me. It's Windows XP.
Windows type command works similarly to UNIX cat.
Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv)
type file1.csv file2.csv > concat.csv
Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv)
When using asterisk(*) to concatenate all files. Please DON'T use same extension for target file(Eg. .csv). There should be some difference in pattern else target file will also be considered in concatenation
type *.csv > concat_csv.txt
At its most basic, concatenating files from a batch file is done with 'copy'.
copy file1.txt + file2.txt + file3.txt concattedfile.txt
In Win 7, navigate to the directory where your text files are. On the command prompt use:
copy *.txt combined.txt
Where combined.txt is the name of the newly created text file.
Place all files need to copied in a separate folder, for ease place them in c drive.
Open Command Prompt - windows>type cmd>select command prompt.
You can see the default directory pointing - Ex : C:[Folder_Name]>.
Change the directory to point to the folder which you have placed files to be copied, using ' cd [Folder_Name] ' command.
After pointing to directory - type 'dir' which shows all the files present in folder, just to make sure everything at place.
Now type : 'copy *.txt [newfile_name].txt' and press enter.
Done!
All the text in individual files will be copied to [newfile_name].txt
I am reiterating some of the other points already made, but including a 3rd example that helps when you have files across folders that you want to concatenate.
Example 1 (files in the same folder):
copy file1.txt+file2.txt+file3.txt file123.txt
Example 2 (files in same folder):
type *.txt > combined.txt
Example 3 (files exist across multiple folders, assumes newfileoutput.txt doesn't exist):
for /D %f in (folderName) DO type %f/filename.txt >> .\newfileoutput.txt
We can use normal CAT command to merge files..
D:> cat *.csv > outputs.csv
cat "input files" > "output files"
This works in PowerShell, which is the Windows preferred shell in current Windows versions, therefore it works. It is also the only version of the answers above to work with large files, where 'type' or 'copy' fails.
Try this:
#echo off
set yyyy=%date:~6,4%
set mm=%date:~3,2%
set dd=%date:~0,2%
set /p temp= "Enter the name of text file: "
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%temp%.txt
This code ask you to set the name of the file after "day_" where you can input the date.
If you want to name your file like the actual date you can do this:
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%yyyy%-%mm%-%dd%.txt
You can do it using type:
type"C:\<Directory containing files>\*.txt"> merged.txt
all the files in the directory will be appendeded to the file merged.txt.
copy is definitely much faster than type - but it sometimes (with large files?) adds a SUB character at the end of the file. So, strictly speaking, it does not simply concatenate the files in the same way as cat in Unix.
So, the correct answer is to use cat - either in something like Git Bash (where it has the same syntax as in Unix), or PowerShell (where it does not).

Why file cannot be found to copy

I am writing a batch script which will copy a file from a folder into the C:\ drive:
#ECHO ON
COPY C:\RANDOMFILES\Weekly Reprort_Hew*.xls C:\Weekly Reprort_Hew???????????.xls
The filename in the RANDOMFILES folder is: Weekly Reprort_Hew, 6-29-2014 10-30-00 PM-642.xls (The date and time and the number at the end will always change so I used the * in the filename being copied in the script)
When I run the batch script, I get the following message:
c:\RANDOMFILES>COPY C:\RANDOMFILES\Weekly Reprort_Hewlett*.xls C:\Weekly Reprort
_Hewlett???????????.xls
The system cannot find the file specified.
How can I fix the issue?
You need double quotes to handle spaces etc. Double check the spelling too.
#ECHO ON
COPY "C:\RANDOMFILES\Weekly Reprort_Hew*.xls" "C:\Weekly Reprort_Hew???????????.xls"
Don't know why it is not working - is it hidden? Maybe the spaces in the name?
The following will work though:
FOR %%I in (C:\RANDOMFILES\Weekly Reprort_Hew*.xls) DO COPY "%%I" C:\
The destination file name isn't necessary; if not otherwise specified, it will remain unchanged provided the destination is different. That may be why the plain COPY command isn't working.
Also:
"It is an not-so-well-known fact that the question mark wildcard will match exactly one character only when the wildcard does not appear at the end of a file name. " from http://www.thefriendlycoder.com/2011/11/24/batch-file-gotcha-question-mark-wildcard/

find (ms-dos command) looking into sub directories files

I am trying to use find to look for files that contain a specific keyword. To my understanding, find takes in a file not a directory (that's why it is giving me error). So is there a way i can go through each sub-directories and look into each and every file to execute the find command so that I can get the result of all files that contains the given keyword? (Much like grep)
So far i got this:
find \S "keyword" "directory\ *"
Error i am getting:
Access denied - Directory name
Access denied - Directory name
.
.
.
Anyone give me a hint? I am current using window 7 right now.
FIND does not take the /s switch (not \s - that's a directory)
FINDSTR is another animal.
About the only quibble about the documentation avaliable from findstr /? from the prompt is that you can target a filemask in a specified directory by specifying \dirname\*, not simply in the current directory as documented. There is also an option to run against a semicolon-delimiter list of directory names - but I've never seen it used.

Editing security setting of a folder through code

I am trying to attach my SQL Server Databases to instance of the server through code. It gives an error that the folder that contains these files does not have 'Full Control' that I need to give by right clicking on the folder, and editing the Securities.
I wish to do it through code. Please advise if it is possible using Netsh command or any other way.
Thanks
You can use xCacls to change NTFS permissions ...
http://support.microsoft.com/kb/318754
"xcacls file name [/T] [/E] [/C] [/G user:perm;spec] [/R user] [/P user:perm;spec [...]] [/D user [...]] [/Y]
where file name indicates the name of the file or folder to which the ACL or access control entry (ACE) is typically applied. All standard wildcard characters can be used. "
The link above gives the rest of the syntax and a couple of examples.

Resources