w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I extract just the last directory from a ZIP archive using 7zip in a Windows batch file?
You have to add the -r unzip option and also add the backticks to the for loop, see below. FOR /F "usebackq tokens=*" %%i in (`DIR *.zip /B /A:-D`) DO CALL :EXTRACT %%i GOTO :EOF :EXTRACT IF "%1"=="" GOTO :EOF SET zipfile=%1 SET folder=%zipfile:~0,-4% 7za.exe x %zipfile% -o%folder% -y -r PackageTmp* GOTO :EOF Backticks are used to execute the command in between them. You can only use them if you add usebackq in the options of the for loop. Executing a command and looping over the results can also be done in the following (more old-fashioned and limited) way with single quotes. FOR /F "tokens=*" %%i in ('DIR *.zip /B /A:-D') DO CALL :EXTRACT %%i See dos command for /? for more info.

Categories : Batch File

Extract a specific file from a zip archive without maintaining directory structure in python
You can use zipfile.ZipFile.read: import os with zipfile.ZipFile(tDir + mainapk[0]) as z: with open(os.path.join(tDir, os.path.basename(icon[1])), 'wb') as f: f.write(z.read(icon[1])) Or use zipfile.ZipFile.open: import os import shutil with zipfile.ZipFile(tDir + mainapk[0]) as z: with z.open(icon[1]) as zf, open(os.path.join(tDir, os.path.basename(icon[1])), 'wb') as f: shutil.copyfileobj(zf, f)

Categories : Python

Extract .tar File to Current Directory Automatically with Shell Script
You can try: -C, --directory DIR change to directory DIR and $(dirname "$x") for file directory for x in in /home/davidwright/attachments/*/*.tar do echo "extracting $x" tar -xvf "$x" -C "$(dirname "$x")" done

Categories : Bash

Extract and Format Information from TAP Archive
Renee pointed me to how Tapper makes it: https://metacpan.org/source/TAPPER/Tapper-TAP-Harness-4.1.1/lib/Tapper/TAP/Harness.pm#L273 Quite some effort to read an archive though...

Categories : Perl

extract 7z archive on linux web hosting
The 7z file format can use various compression algorithms, so you might be able to decompress the archive with one of the existing utilities for bzip2 or deflate. You will likely need to use a library such as this one though. Here is the latest version.

Categories : PHP

Python: How do i get the name of the current archive?
The variable __file__ contains the path to the current python file. So If you have a structure: . `- your.egg `-your_module.py And in your_module.py you have a function: def func(): print(__file__) The the code: import sys sys.path.append('/path/to/your.egg') from your_module import func func() Will print out: /path/to/your.egg/your_module.py So basically you can manipulate the __file__ variable if you know where relatively your module is inside the egg file and get the full path to the egg. To get the relative path to the egg in the script that's in the egg file you'll have to do: def rel_to_egg(f): my_dir = os.path.dirname(os.path.abspath(f)) current = my_dir while not current.endswith('.egg'): current = os.path.dirname(current) return os.path

Categories : Python

How to use Archive::Extract safely - againist zip bomb or similar?
$Archive::Extract::PREFER_BIN = 1 doesn't protect you against zip bombs, you are passing the problem to the binary unzip tool of your system. This SO question may helps you. I like the idea of running a second process with ulimit.

Categories : Perl

Extract original file from CAB archive and determine version (.net CE 2.0 app)
Although this is a quite old question, here is one answer: Windows CE CAB files are created with CabWizard normally. The contents of these CAB files can be viewed/listed with some archive apps like extract or 7z for example. The file names are mangled and the file names are mapped within a xml file inside the CAB: Sample file list: 000KBDUS.002 0MSTSCAX.003 00MVKLIB.004 0TSCSCAN.006 00WPCTSC.005 FILTER~1.001 REMOTE~1.000 REMOTE~1.008 _setup.xml TSCSHIFT.007 You see the _setup.xml file. It lists the file mappings (mangled to real file name) and some more information: <wap-provisioningdoc> <characteristic type="Install"> <parm name="InstallPhase" value="install"/> <parm name="AppName" value="Microsoft Remote Desktop Mobile"/> &l

Categories : C#

Svn how to archive old tags in a new directory
You can use the regular move operation to move tags from one directory to another directory. Using the command line client somewhere in the working directory, this looks as follows: svn mkdir ^/old-tags svn mv ^/tags/foo ^/tags/bar ^/tags/baz ^/old-tags If you have a huge number of tags, and want to filter them automatically, then build the command line based on the output of svn ls ^/tags. Here is an example how this might look with bash: svn mv $( svn ls ^/tags | sed -ne '/^ba.*$/s//^/tags/&/p' ) ^/old-tags/

Categories : Svn

How to get the top level parent term related to the current archive page?
I think I figured it out. I ended up with the following: $term_id = get_queried_object()->term_id; //Get ID of current term $ancestors = get_ancestors( $term_id, 'product_category' ); // Get a list of ancestors $ancestors = array_reverse($ancestors); //Reverse the array to put the top level ancestor first $ancestors[0] ? $top_term_id = $ancestors[0] : $top_term_id = $term_id; //Check if there is an ancestor, else use id of current term $term = get_term( $top_term_id, 'product_category' ); //Get the term echo $term->name; // Echo name of top level ancestor Perhaps there is a better way to do this, but this seems to work fine.

Categories : Wordpress

query only direct child and sub-terms of a current term archive
I think you could do something like <?php $taxonomy = 'product_cat'; // get the term IDs assigned to post. $post_terms = wp_get_object_terms( $product->id, $taxonomy, array( 'fields' => 'ids' ) ); // separator between links $separator = ', '; if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) { $term_ids = implode( ',' , $post_terms ); $terms = wp_list_categories( 'title_li=&style=none&echo=0&child_of=' .get_queried_object_id() . '&taxonomy=' . $taxonomy . '&include=' . $term_ids ); $terms = rtrim( trim( str_replace( '<br />', $separator, $terms ) ), $separator ); // display post categories echo $terms; } ?>

Categories : Wordpress

Tar a directory, but don't store full absolute paths in the archive
tar -cjf site1.tar.bz2 -C /var/www/site1 . In the above example, tar will change to directory /var/www/site1 before doing its thing because the option -C /var/www/site1 was given. From man tar: OTHER OPTIONS -C, --directory DIR change to directory DIR

Categories : Linux

How to change the current working directory to a specific directory and execute a program under the specific directory?
One of your principal problems is that you don't capture the return value (output) of the command in backticks. You are merely throwing away the output you want. Do something like: my $output = `perl ./script.pl` system("perl ./script.pl")

Categories : Perl

Python joining current directory and parent directory with os.path.join
You can use normpath, realpath or abspath: import os goal_dir = os.path.join(os.getcwd(), "../../my_dir") print goal_dir # prints C:/here/I/am/../../my_dir print os.path.normpath(goal_dir) # prints C:/here/my_dir print os.path.realpath(goal_dir) # prints C:/here/my_dir print os.path.abspath(goal_dir) # prints C:/here/my_dir

Categories : Python

After I deleted a directory, it always prompts "shell-init error retrieving current directory getcwd solve" when log on bash
When opening a new shell or xterm, it's started in the working directory of the process that started it. If you e.g. cd /proc && xterm, the new terminal will place you in /proc. Whatever's starting your terminal had positioned itself in /home/desktop/zeno, and now all the terminals are trying to start there. If you make that process change directory (by rebooting, for example), the terminals will start in a directory that exists and you will no longer get this error.

Categories : Linux

How to print the name of my current directory's parent directory
You can use ${PWD%/*}: $ echo $PWD /home/me/test/t $ echo ${PWD%/*} /home/me/test As the expression ${string%substring} Strips shortest match of $substring from back of $string (reference).

Categories : Shell

Get the current directory name via php script in another directory
I am not 100% sure of your questions, but it sounds like you are looking for the URL/Directory of the page you are currently on, not the directory of the header? What about: $_SERVER['PHP_SELF']; $_SERVER['REQUEST_URI']; $_SERVER['SCRIPT_NAME']; $_SERVER['SCRIPT_FILENAME']; $_SERVER['DOCUMENT_ROOT']; Those all give info about the current file open by the server based on the HTTP request it received.

Categories : PHP

Create batch to archive files using main folder name for archive name
I don't have WinRAR, so I can't check the syntax for the rar command, but you could create a batchfile (backup.bat) like: cd %1 "C:Program FilesWinRARWinRAR.exe" a -esh -m5 -mt2 -r -s -t "..\%1.rar" cd .. And invoke it with backup A from the temp folder. That might be a start...

Categories : Batch File

Archive old files only AND re-construct folder tree in archive
I would take this route instead of rsync: Change directories so we can deal with relative path names instead of absolute ones: cd /home/user/documents Run your find command and feed the output to cpio, requesting it to make hard-links (-l) to the files, creating the leading directories (-d) and preserve attributes (-m). The -print0 and -0 options use nulls as record terminators to correctly handle file names with whitespace in them. The -l option to cpio uses links instead of actually copying the files, so very little additional space is used (just what is needed for the new directories). find . -type f -mtime +1000 -print0 | cpio -dumpl0 /home/user/archives Re-run your find command and feed the output to xargs rm to remove the originals: find . -type f -mtime +1000 -print0 | xargs

Categories : Linux

PHP Zip: Extract contents of a directory
I managed to get it to work by working with file streams manually instead of using extractTo(). The script extracts all the files in the base of the archive and all the files in directories in the base of the archive in to the output folder. For example, if this is the archives contents: - d0001 - My Folder - view.php - tasks.txt - file1.txt - picture1.png - document.doc - d2 - another1.png - pic2.gif - doc1.txt - mylist.txt The contents of the output directory will look like this: - My Folder - view.php - tasks.txt - file1.txt - picture1.png - document.doc - another1.png - pic.gif - doc1.txt - mylist.txt The code: function rrmdir($dir, $removebase = true) { if(is_dir($dir)) { $objects = scandir($dir); foreach($objects as $object) {

Categories : PHP

Using BeautifulSoup to extract current version of Firefox
The print version syntax works fine in Python 2.4, it shouldn't generate a syntax error. Verify that that's really the version in use, because in Python 3.x print version will cause a syntax error. Just to be sure, check if this works: print(version).

Categories : Python

Gradle extract multiple dependencies each to a different directory
I found a working solution. Don't know if it's the best way, but this is what I came up with: task extractDeps << { configurations.cppDependencies.resolvedConfiguration.resolvedArtifacts.each { artifact -> copy { from project.zipTree(artifact.getFile()) into new File(project.buildDir, "DEP_DIR/" + artifact.name) } } }

Categories : Java

iOS - dirent.h - current directory name
See `NSFileManager as it provides the standard iOS interface to the filesystem. https://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html As well, you should understand this thoroughly. https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemProgrammingGuide.pdf (See the iOS section)

Categories : IOS

Get current batchfile directory
System read-only variable %CD% keeps the path of the caller of the batch, not the batch file location. You can get the name of the batch script itself as typed by the user with %0 (e.g. scriptsmybatch.bat). Parameter extensions can be applied to this so %~dp0 will return the Drive and Path to the batch script (e.g. W:scripts) and %~f0 will return the full pathname (e.g. W:scriptsmybatch.cmd). You can refer to other files in the same folder as the batch script by using this syntax: CALL %0..SecondBatch.cmd This can even be used in a subroutine, Echo %0 will give the call label but, echo "%~nx0" will give you the filename of the batch script. When the %0 variable is expanded, the result is enclosed in quotation marks. More on batch parameters.

Categories : Batch File

How do I obtain and use the current directory of the exe?
Use: File.Copy(SelFolder & "Resource.zip", progDirectory) Instead of: My.Computer.FileSystem.WriteAllBytes(SelFolder & "Resource.zip", progDirectory, False)

Categories : Dotnet

How to Keep Ace from Looking for Themes and Modes in Current Directory?
I find with Ace and MVC Bundling and Minification, I need to set the basePath in the ace configuration using an absolute reference. ace.config.set("basePath", "/Scripts/FullPathToMy/AceEditorDirectory"); It's probably not the best solution, but it should get you on your way.

Categories : C#

obtaining Current directory in VC++ forms
You are passing the address of the pointer to Convert::ToString(). pwd is an array and using the variable name without an array subscript automatically decays to a pointer. You want to use either Convert::ToString(pwd) or Convert::ToString(&pwd[0])

Categories : Visual C++

log4j.xml in current directory not found
For Eclipse testing in Maven the easiest thing I've found to do is to put the log4j.xml in src/test/resources. It will be added to the classpath when running unit tests, etc. When we actually install our application at a customer site we place the file in /etc/... and specify it with -Dlog4j.configuration. My best guess as to why the current directory part isn't working for you is that Eclipse is probably setting the current directory to something other than what you think it is. Try following the instructions here to print the current working directory and check it matches what you think. UPDATE: Almost forgot. When you specify -jar the classpath options (-cp -classpath) are ignored. -jar Execute a program encapsulated in a JAR file. The first argument is the name of a J

Categories : Java

How to get the current working directory using python 3?
It seems that IDLE changes its current working dir to location of the script that is executed, while when running the script using cmd doesn't do that and it leaves CWD as it is. To change current working dir to the one containing your script you can use: import os os.chdir(os.path.dirname(__file__)) print(os.getcwd()) The file variable is available only if you execute script from file, and it contains path to the file. More on it here: Python __file__ attribute absolute or relative?

Categories : Python

Zip together all HTML files under current directory
What about this? find /your/path/ -type f -name "*.html" | xargs zip all_html_files.zip looks for all .html files under the directory /your/path (change it for yours). Then, pipes the result to xargs, which creates the zip file. Edit To junk the paths, add -j option: find /your/path/ -type f -name "*.html" | xargs zip -j all_html_files.zip

Categories : Linux

What is the difference between these ways of getting current directory?
They all give the same result They certainly don’t. currentDir and dir both give you the current working directory – i.e. by default the directory your executable was run from (but it can be changed during the execution). By contrast, appBaseDir and path get the directory which contains the executing assembly’s file. To illustrate how they differ, consider that you have an executable which sits in C:araz.exe. Now I can execute the application by entering the following chain of commands in a terminal: $ md C:foo $ cd C:foo $ ..araz.exe Now the current working directory is C:foo but the application’s base directory is C:ar. There exist analogous means of setting the working directory for other methods of launching an application (e.g. via a shortcut icon or programmat

Categories : C#

jQuery/JS: Get current URL parent directory
Fiddle var a = "http://www.site.com/example/index.html"; var b = a.substring(0, a.lastIndexOf('/'))+"/";

Categories : Javascript

mod_rewrite rewritebase current directory
this does exactly that, through it looks too scary to use http://www.zeilenwechsel.de/it/articles/8/Using-mod_rewrite-in-.htaccess-files-without-knowing-the-RewriteBase.html googled by mod_rewrite htaccess directory current directory

Categories : Htaccess

NPM Installs Package Outside Current Directory
If the node_modules directory doesn't exist in your current directory, NPM will look for it in the higher directories until it finds it. So, if the parent directory has a node_modules directory, NPM will assume that's where it is to install modules. A quick way around this is to create an empty node_modules directory where you want the modules to be placed.

Categories : Node Js

Get current Word document's save directory
ActiveDocument.FullName The above gives the full path to the document, including the file name. ActiveDocument.Path The above gives the directory where your document is saved. ActiveDocument.Name The above gives the name of the document, without path information.

Categories : Vba

Why pipe resets current working directory?
The pipe does not reset the current working directory. The pipe creates subshells, in bash one for each side of the pipe. The subshell also does not reset the current working directory. The subshell contains the changes to the environment in itself and does not propagate them to the parent shell. In your first script: $ { mkdir dir; cd dir; pwd; } | cat; pwd; The cd is executed inside the left subshell of the pipe. The working directory is changed only in that subshell. The working directory of the parent shell is not changed. The first pwd is executed in the same subshell as the cd so it reads the changed working directory. The pwd at the end is executed in the parent shell so it reads the working directory of the parent shell which was not changed. In your second script: $ { mkdir

Categories : Bash

Textmate 2 Ruby Run settings for current directory
First of all, this has nothing to do with Textmate but with how Ruby handles that file path. So no need to fiddle with TM settings. You are opening a file relative to the current working directory. If you run Test1.rb from the RubyDevs directory Test2.rb is not present in the current working directory, if you open the file from the RubyLearn directory it is. To make it work from any directory you need to determine the directory of the Test1.rb file and add the Test2.rb path like this: file = File.open(File.dirname(__FILE__) + '/Test2.rb') file.close() Hope this helps!

Categories : Ruby

How to run a process from memory/RAM as the "current working directory"
It sounds difficult, and it will definitely require a lot of stuff that cannot be done in pure Java. On Linux, I think you would need to do the following: Create and mount a "tmpfs" - http://unix.stackexchange.com/questions/66329/creating-a-ram-disk-on-linux Unzip the ZIP file into the tmpfs Run the .exe using ProcessBuilder ... which allows you to set the child processes current directory. etcetera Unmount the "tmpfs" when you've done. The commands for creating the "ram disk" file system will be OS specific, and may require root / administrator privilege. It is unclear whether doing this will be more efficient than using a temporary directory in the file system. I wouldn't attempt this unless there was a clearly demonstrated need for a solution that it more efficient; i.e. unle

Categories : Java

How to change the current working directory in Groovy
As Groovy runs on JVM, the same restrictions apply. Unfortunately it is not possible. Changing the current working directory in Java? JDK bug

Categories : Groovy

Display the names of all .txt documents within the current (or specified) directory
This should work: File folder = new File("path/to/txt/folder"); File[] files = folder.listFiles(); File[] txtFiles = new File[files.length]; int count = 0; for(File file : files) { if(file.getAbsolutePath().endsWith(".txt")) { txtFiles[count] = file; count++; } } It should be pretty self explanatory, you just need to know folder.listFiles(). To trim down the txtFiles[] array use Array.copyOf. File[] finalFiles = Array.copyOf(txtFiles, count); From the docs: Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.