I am having a bad time with the standalone version of 7-Zip. I want to compress a folder with a password. I tried: 7za a my_folder -pmy_password. It's compressing all the files in which 7za.exe is located with file name of my_folder.
BTW: I am using a scripting language called AutoIt.
As per Command Line Syntax (7zip.chm) > Contents > Command Line Version > Syntax :
7za <command> [<switch>...] <base_archive_name> [<arguments>...]
<arguments> ::= <switch> | <wildcard> | <filename> | <list_file>
<switch>::= <switch_symbol><switch_characters>[<option>]
<switch_symbol> ::= '/' | '-'
<list_file> ::= #{filename}
a is the command.
-pmy_password is a switch and should be therefore after the command and not at end. But switches can be also appended after base archive file name although this makes it more difficult to read and parse.
my_folder should be an argument, but is interpreted as base archive file name because you have not specified any archive file name.
So try:
7za.exe a -r -pmy_password MyArchive.zip my_folder
Related
I'm working on creating a batch script which will allow me delete files with the same name and an appended ascending number; for example:
fileName.txt
fileName (1).txt
fileName (2).txt
fileName (3).txt
fileName (4).txt
fileName (5).txt
fileName (6).txt
fileName (7).txt
etc....
Below is the code I came up with, but it only deletes the file name, without the appended number in the parenthesis.
#echo off
:: Change to the Downloads directory
cd %UserProfile%\Downloads
:: Deletes files
Del Awesome-Kicks-Test_File-Run.txt
All of these file are saved in my Downloads directory.
Could you please direct me on how best to go about deleting these files?
Since you are on Windows, you should have access to PowerShell. PS has much better support for these types of operations, and is available on all versions of Windows in common use.
One method is to use a regular expression to find all of the files that match the pattern. Here is a basic one that should work for the example you gave: fileName \(\d+\)
Using PowerShell, you then combine that regular expression with the Get-ChildItem, Where-Object and Remove-Item commandlets.
Get-ChildItem | Where-Object { $_.Name -match 'fileName \(\d+\)' } | Remove-Item
i have 126 folders in the same directory with names like this
"5d843c63-2043-499b-abd6-6ea0bbde5f58"
each folder contain 1 #pdf file
i want to move each file to one
i have used the command and managed to locate all the pdfs in the separated folders
locate ~/Desktop/wps\ /*pdf
then i used the " | " to move them at once but i couldn't i use the commnad
locate ~/Desktop/wps\ /*pdf | mv ~/Desktop/pdffff/
STOUD be like mv: missing destination file operand after '/home/yousef/Desktop/pdffff/'
using ubuntu
I don't know the locate command, but if it returns a list of paths of the files you want, do
mv `locate ~/Desktop/wps\ /*pdf` /path_to/new_folder_to_store_pdfs
The backticks ` ` will execute the locate command first, then the output of locate will be substituted into the outer mv command.
I did it just now with find and it worked.
mv `find -name *pdf` new_folder
My script fetches the names of directories in a path and stores in a text file.
#!/bin/bash
MYDIR="/bamboo/artifacts"
DIRS=`ls -d /bamboo/artifacts/* | cut -d'/' -f4 > plan_list.txt`
plan_list.txt:
**************
PLAN1
PLAN2
PLAN3
Now I am trying to pass each of these directory names to a URL to get output like this.
http://bamboo1.test.com:8080/browse/PLAN1
http://bamboo1.test.com:8080/browse/PLAN2
http://bamboo1.test.com:8080/browse/PLAN3
The script to do that doesn't seem to work
bambooServer="http://bamboo1.test.com:8080/browse/"
for DIR in $DIRS
do
echo `$bambooServer+$DIR`
done
Could someone please tell me what I am missing here? Instead of storing the ls command output to a plan_list.txt file i tried passing to array but that didn't work well too.
DIRS=`ls -d /bamboo/artifacts/* | cut -d'/' -f4 > plan_list.txt`
DIRS is just an empty variable since your command is not producing any output and just redirecting output to plan_list.txt.
You can rewrite your script like this:
#!/bin/bash
mydir="/bamboo/artifacts"
cd "$mydir"
bambooServer="http://bamboo1.test.com:8080/browse/"
for dir in */
do
echo "$bambooServer$dir"
done
*/ is the glob pattern to get all the directories in your current path.
I am looking for a script to rename files and directories that have special characters in them.
My files:
?rip?ev <- Directory
- Juhendid ?rip?evaks.doc <- Document
- ?rip?ev 2 <- Subdirectory
-- t?ts?.xml <- Subdirectory file
They need to be like this:
ripev <- Directory
- Juhendid ripevaks.doc <- Document
- ripev 2 <- Subdirectory
-- tts.xml <- Subdirectory file
I need to change the files and the folders so that the filetype stays the same as it is for example .doc and .xml wont be lost. Last time I did it with rename it lost every filetype and the files were moved to mother directory in this case ?rip?ev directory and subdirectories were empty. Everything was located under the mother directory /home/samba/.
So in this case I need just to rename the question mark in the file name and directory name, but not to move it anywhere else or lose any other character or the filetype. I have been looking around google for a answer but haven't found one. I know it can be done with find and rename, but haven't been able to over come the complexity of the script. Can anyone help me please?
You can just do something like this
find -name '*\?*' -exec bash -c 'echo mv -iv "$0" "${0//\?/}"' {} \;
Note the echo before the mv so you can see what it does before actually changing anything. Otherwise above:
searches for ? in the name (? is equivalent to a single char version of * so needs to be escaped)
executes a bash command passing the {} as the first argument (since there is no script name it's $0 instead of $1)
${0//\?/} performs parameter expansion in bash replacing all occurrences of ? with nothing.
Note also that file types do not depend on the name in linux, but this should not change any file extension unless they contain ?.
Also this will rename symlinks as well if they contain ? (not clear whether or not that was expected from question).
I usually do this kind of thing in Perl:
#!/usr/bin/perl
sub procdir {
chdir #_[0];
for (<*>) {
my $oldname = $_;
rename($oldname, $_) if s/\?//g;
procdir($_) if -d;
}
chdir "..";
}
procdir("top_directory");
I want to create a windows batch file (Win7) to achieve the following:
Copy source.doc to destination with destinationFilename.doc taken from a list in a text file (nameList.txt)
I have batch file that will make directories from nameList.txt but I can't figure out how to modify the batch file to make it copy source.doc in the required manner.
Using xargs you can process a file nameList.txt which contains a newline separated list of target filenames like this:
cat nameList.txt | xargs -I "F" cp source.doc F
where -I "F" defines F as a placeholder to be used in command invocation of cp.