Mv file problems when moving file back in path - powershell

I am completing Zed Shaw's Learn Python the Hard Way and am stuck on a concept in the appendix command line crash course in Windows PowerShell.
My problem is with the move (mv) command, specifically moving a file farther back in the path (hope that makes sense). Here is what I did:
I created a directory called temp, and within that directory created a .txt file called awesome.txt and another dirctory called newplace. Then, I write the command "mv awesome.txt newplace" and the awesome.txt file is moved to the directory newplace. Great!
The problem is that I want to move the file awesome.txt back to its original place in the directory temp. When I change my working directory to the directory newplace "cd newplace" and then type "mv awesome.txt temp" the file awesome.txt does not move back to the directory temp, but instead converts from a .txt file to a "file" and stays put in the newplace directory.

Folders like this are nested inside each other:
c:\temp
c:\temp\newplace\
When you cd around, you go into a folder (, e.g. cd temp:
c:\temp\ (o_o)
c:\temp\newplace\
And you can only see things in the same folder you are in. So you can move into newplace because that name makes sense where you are. But when you are in newplace
c:\temp\
c:\temp\newplace\ (o_o)
You can't move to temp because you don't know where it is. You don't have an index of every directory name on the entire computer that you can shortcut to, you only have two options: something in the same place you are, or something with an absolute path - a full name of where it is. c:\temp\.
So mv awesome.txt temp tries to put it inside temp where you are -> c:\temp\newplace\temp\ -> that doesn't exist, so it assumes you're moving it to a new name in the same place.
You would need mv awesome.txt c:\temp\ to specify it properly.
Except there's a sneaky shortcut, anywhere you are, there is automagically a path called .. which means the folder one <-- thatway from where I am.
So you could mv awesome.txt ..\ to push it back one level in the path, without needing to know exactly where that is. This is probably what Zed Shaw is expecting.

Related

moving files to different folders from 1

I have 200,000 files I want to send to different folders based on key words in the file name
in English if a file name has (shtf or prepper or prepping or survival) in the name send(move) it to folder shtf
if a file has (cookbook or gluten or recipe) move to food folder
*cookbook* *GLUTEN* *RECIPE*
example
(file name)
more shtf tips.epub move to folder shtf
ifshtfbeready.epub move to folder shtf
oldworldcookbook.epub move to folder food
i'm old retired ibmer small basic sas dos commands or ????
Here is a bash command, you may be able to adapt it into dos etc. I'm posting this because others may it useful as well.
find . | grep -E "(cookbook|gluten|recipe)" | while read name; do mv $name directory; done;
Where directory is the name of the directory you want to move the file. You can replace . with whatever starting directory you want, of course.
You can use wildcard in the source filename list and use a directory as the target to move multiple files with one command.
move c:\dir1\*cookbook*.* c:\food
move c:\dir1\*gluten*.* c:\food

Is it possible to set output directory for triangle program from triangle package?

I see no way to set destination directory or file here: http://www.cs.cmu.edu/~quake/triangle.switch.html
Actually, the program places result file in the same directory, even if current directory is different.
Why? Is ti possible to change?
The output files for the program are generated from the input file names. You can see this from the source code on line 3586
strcpy(b->outnodefilename, b->innodefilename);
...
strcat(b->outnodefilename, ".node");
strcat(b->outelefilename, ".ele");
...
Because of that I don't think there is a way to set the output directory as an option. It seems you will need to manually copy the output files to a different directory
cp output.node your/output/dir/output.node && rm output.node

7zip / winrar command to extract a folder with path intact to specific folder but excluding parent source path

example
There is a file "sample.rar".
Folder structure is: "rising\dawn\ and here there are many (folders1, folders2 and file1, file2)" in this archive.
i have used following command
7z.exe x "sample.rar" "rising\dawn\*" -oi:\delete
The result is:
all files and folders in "rising\dawn\" are extracted to "i:\delete" folder but the empty parent folders "rising\dawn\" are also created in destination folder.
e.g. destination looks:
i:\delete\rising\dawn\folder1\file1.bmp
i:\delete\rising\dawn\folder2\subfolder
i:\delete\rising\dawn\file1.txt
i:\delete\rising\dawn\file2.txt
i don't want "rising\dawn\" empty folders to be created but the folder structure there onwards must be as is in the archive.
i want the result:
i:\delete\folder1\file1.bmp
i:\delete\folder2\subfolder
i:\delete\file1.txt
i:\delete\file2.txt
at last i found a way out solution. thanks to the winrar support. i have accepted it as an answer below.
if you find the question useful don't forget to click the up-vote button.
Finally this gave me the result.
Thanks to winrar support.
rar x -ep1 sample.rar rising\dawn\* d:\e\delete\
i have tried other answers given here, this is the only correct answer.
don't forget to upvote.
You can extract the archive normally and
1) move the lower level folder/files to where you would like it, then
2) remove the extra top level archive folders.
Code to do so will depend on the exact task.
Using e command instead of x and add -r option works well.
Like this:
7z.exe e -r "sample.rar" "rising\dawn\*" -oi:\delete
My executable version is "7-Zip [64] 9.20 2010-11-18",
And the platform is Windows 8.1.
This command line eliminates unnecessary parent folders and preserves the hierarchy of folders.
You need to use the e command rather than the x command:
7z.exe e "sample.rar" "scholar\update\*" -oi:\delete
Using e instead of x means 7zip will extract all matching files into the same folder (as specified via the -so switch, or the current directory if this isn't specified) rather than preserving the folder structure from inside the archive.

Matlab function call directory

So i had this issue that occurred when I ran a Matlab script. Here is an a simple example that illustrates it:
So its important to outline the file structure:
MainFolder
script.m
SubFolder
a1.csv
a2.csv
a3.csv
now say i have a script like this:
-> script.m
dir
it would simply print out the files in the folder.
Now the wierd thing, if i run the script in the Subfolder like this:
>>script
it will do this:
>> a1.csv a2.csv a3.csv
but if i do this in the folder:
>>run('C:\Users\....\MainFolder\script.m')
it will only print out
>> script.m
So obviously it is acting as if i ran it form MainFolder rather than SubFolder.
What is the point of this functionality?
The dir command shows the directory contents of Matlab's current directory, not that of where the script is located. So the script showed you the directory contents of wherever you happened to be in the Matlab command prompt when you called that script.
To get what you want, use this in the script:
dir(fileparts(mfilename('fullpath')))
Use pwd to see current dir
Use cd to change directory
Use path to see if your project folders are included in the path
Use which to see you are calling the right *.m file (in case there is multiple .m files with same name on the path)

Linux recycle bin script

I'm creating a recycle-bin script in SH shell linux in three differant scripts, delete, trash and restore.
The first two scripts are working fine; 'Delete' moves the selected file to the recycle-bin while logging a text file called 'trashinfo' which shows the original path location of the file (to be later used in restore) and 'Trash' which removes everything in the recycle-bin.
The 'restore' script should take the logged path name gained in the delete script and return the file to its original location. I've spent more time than I'd like to remember on this and cant get the restore script to work properly!
Below is the script I've written, as far as I can make out I'm grepping for the filename variable in the text file that holds the pathname, eg 'restore testfile', this is then combined with the basename command, the testfile is then moved into the location thats been grepped and combined with the basename.
Anyone have any pointers on where I'm going wrong?
if [ "$*" != -f ]
then
path=grep "$*" /usr/local/bin/trashinfo
pathname=basename "$path"
mv "$path" "$pathname"
path=$(grep "$*" /usr/local/bin/trashinfo)
pathname=$(basename "$path")