Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a file that I have downloaded from Google (it is inside the download folder)
and I want to move it to the autorun folder ( The folder where files run when the computer turns on).
I need to move the file using a cmd command ( the reason why is that it's going to be done using the USB rubber ducky.
I am using windows 10 64 bit if it is any help.
The path where the file is
C:\Users\%USERPROFILE%\Downloads\Test.exe
and the path I want to move it to is
C:\Users\%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
The reason why %USERPROFILE% is that it should work on all computer.
To move a file, you use the move command.
move "%USERPROFILE%\Downloads\Test.exe" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
I put quotes around the source and target in case you're one of those people who has spaces in their username for some reason (and the target needs them anyway for the spaces in "Start Menu").
From the output of move /?:
Moves files and renames files and directories.
To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
[drive:][path]filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a
directory name, or a combination. If you are moving
only one file, you can also include a filename if
you want to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.
/Y Suppresses prompting to confirm you want to
overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite
an existing destination file.
To move file use mv, but not working if you don't do with admin, how you can hack, try superuser tools for windows!
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 9 months ago.
This post was edited and submitted for review 9 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have tried numerous methods of doing this including Remove-Item, rmdir, del, and rd. I have seen similar questions, but none of the answers have helped me. To be clear, I am not asking for a specific "book, tool, or software library"; I just want a Batchfile command to recursively delete a folder. I'm sorry if I'm doing something wrong; I'm pretty new here.
To delete a non empty folder, you need something called recursion. What we usually read is that we want to "delete a folder recursively", which means to delete a folder and all its contents, including other folder, with their respective contents and folders, and so on.
The command del does it for you. Have you read its help or its documentation? To see that, the command you use in the cmd program is:
del /?
But this does not directly answer your question. What you need to put in your batch file is:
del /s /q [non empty folder name]
"/s" is to delete it recursively
"/q" is to delete it without asking for confirmation of each file or folder being deleted. You may want to remove this item, if you want to choose what will be deleted inside the folder.
You must not write the square brackets I wrote in the command example. Just the folder name, as it is.
For the previous answer, I checked the current Microsoft documentation about commands it has, and it does NOT say clearly that the del command will delete only files.
The command you need to recursively delete a folder, and all files OR folders it contains is:
rmdir [name of the folder] /s /q
Please note the "/s" and "/q" arguments, which have the same meaning as for the del command, but they come AFTER the name of the folder! This is what the command documentation shows, as you may read here.
But there are more possible reasons for the recursive directory deletion failing! If you try to delete a directory that has system files or hidden files, the rmdir command will fail. To solve this problem, you need to do more work. To quote the documentation pointed above:
You can't delete a directory that contains files, including hidden or system files. If you attempt to do so, the following message appears:
The directory is not empty
Use the dir /a command to list all files (including hidden and system files). Then use the attrib command with -h to remove hidden file attributes, -s to remove system file attributes, or -h -s to remove both hidden and system file attributes. After the hidden and file attributes have been removed, you can delete the files.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm newbie in batch script. How to write a script on copying specific file from a network folder to my drive D:\
Example:
The filename is ABC021318X.zip, where 021318 is a date while ABC and X are constants. When the script is running it will prompt user to enter the date with a format of mm/dd/yy, then when I hit Enter, it will copy ABC(specified date)X.zip from a network folder to D: drive
Further, when file is not found, it will give a message:
FILE NOT FOUND!
Hoping someone with the relevant knowledge can help me out.
Thanks in advance.
Simply do:
#echo off
set /p "mydate=Please Enter date (MMddYY) : "
set "mydate=%mydate:/=%"
copy /Y Z:\AB%mydate%X.zip D:\
Where Z:\ is the network drive in this case.
Note, in this case users can add the date as MMddYY i.e 021418 or MM/dd/YY i.e 02/14/18 as it will strip out / if it exists.
Automatically, if file is not found, it will print error
The system cannot find the file specified.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I would like to write a bat script to do the following:
Use 7 Zip to extract files from an existing zip file, into a folder by the same name as the original zip file (bar the .zip extension), and keeping the file & directory structure that was contained in the zip file.
I can extract all the same files into the current directory, by using
"C:\Program Files (x86)\7-Zip\7z.exe" e myZipFile.zip
Reading the help of the 7z-command by just typing "C:\Path To\7-Zip\7z.exe" gets the help with all possible arguments. Here we find the following interesting ones:
e : Extract files from archive (without using directory names)
and
x : eXtract files with full paths
Trial and error shows that the latter is the one fitting your desired behaviour without bigger effort :)
After the comment by #BadmintonCat here is the addition that will create a folder to zip everything into (use as batch script with the file as argument):
#echo off
SET "filename=%~1"
SET dirName=%filename:~0,-4%
7z x -o"%dirName%" "%filename%"
From the help: -o{Directory} : set Output directory. 7z will create the directory if it does not already exist.
Just use the command: 7z x *.zip -o\*
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am using Audacity's Chains scripting function to batch-convert and edit many large, uncompressed .WAV files at once to a much smaller .OGG format. I end up with a folder structure like the following:
f:/sound-recordings:
-- rec1.wav
-- rec2.wav
-- rec3.wav
-- rec4.wav
-- rec5.wav
f:/sound-recordings/cleaned:
-- rec1.ogg
-- rec2.ogg
-- rec3.ogg
Some of the source .WAV files are corrupted (note rec4.wav and rec5.wav in above example), and Audacity will not convert them (at least through the chains function). This creates a problem, as it can become very tedious to compare the two folders, and delete only the .WAV files which were successfully converted to .OGG.
In the example above, "rec1.wav", "rec2.wav", and "rec3.wav" should be deleted, while "rec4.wav" and "rec5.wav" are untouched, since they weren't converted.
I need a script (batch or python preferred) to delete any .WAV files from the main folder, that have identically named .OGG files located in the "cleaned" folder, leaving other .WAV files untouched.
#echo off
for %%I in (f:\sound-recordings\*.wav) do (
if exist f:\sound-recordings\cleaned\%%~nI.ogg del %%I
)
You can create a list of the elements in the clean directory, using split to strip off the extension and then iterator through the dirty directory checking if it is in clean.
Basic python pseudo-code would look like:
clean = [filename.split('.')[0] for filename in clean_directory]
delete = [filename for filename in dirty_directory if filename.split('.')[0] in clean]
for filename in delete:
os.remove(filename)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to parse a txt file and I want to reference it relative to my current directory location. If I put the file path in completely it will work but it I try to use
..\src\test.txt it wont find it. Is this not the proper way to reference a file relative up one directory?
Any help would be appreciated
If you put "..\src\test.txt" in a string constant, you need to double all the backslashes so that "\t" and "\s" are not interpreted as escape sequences. (Or you can use forward slashes instead, which is more portable.)
It will depend on what the current working directory is set to. By default it is the directory the executable resides in if you double-click the app from Explorer, or the current path the shell is in if started from a command prompt.
If test.txt is in c:\code\app\src and your application is in c:\code\app, the relative path "..\src\test.txt" is going to end up c:\code\src\test.txt (if launched from explorer).
Try printing the output of _getcwd before you try opening the file to verify what directory is the current working directory.
Assuming that your directory structure looks like:
project
+---src
| test.txt
| proj.c
\---bin
a.out <- Working directory
your relative path is correct; your working directory is actually on the same level as the text file.
If you really mean that the file is up one directory as you stated, like this: (Note: This is an awkward project structure)
project
\---src
| test.txt
| proj.c
\---bin
a.out
or like this: (makes more sense)
project
| test.txt
+---src
| proj.c
\---bin
a.out
Then the path you need is "../test.txt" or, equivalently, "../../project/test.txt"
A better location would be in a data directory, so your path would be "../data/test.txt"
I guess this is a windows VS vbuild (given the back slashed path)
VS will have put the binary in something like project\bin\debug. And when you run it in VS it will set the current WD to the location of the binary.
so
a) copy the file to the right place
b) change the project properties debug setup to say set the current path to the place where you expect the file to be (relatively)