Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a file 1

Status
Not open for further replies.

dik

Technical User
Jul 18, 2001
217
0
16
MD
I have a Portable HDD with movies on it. I can watch the movies, but cannot delete the files.
I get an error as follows:

Clipboard01_yk2ezc.jpg


Any suggestions on how to delete this? Is there a utility that can be used to erase 'stubborn' files. I remember in Basic, there was a Kill command that would take out most files.

Thanks, Dik
 
Have you run chkdsk against the drive the problematic file is saved on?
 
Thanks... it did the trick.

Another question. I want to do a DIR command to get the names of all the files.ext on a HDD, without the paths and other data, going into sub-directories. Is it possible to use a series of 'switches' for the DIR command to do this? and can I redirect them to a file like '>> movies.txt' like I used to do in DOS?

thanks, Dik
 
dir *.ext/s | files.txt

That should do the trick.

I've got nothing to hide, and I demand that you justify what right you have to ask.
 
Not really easy with the DIR command (although you can create a command that parses the output of the DIR command, dissects it and spits out what you want), but using For is probably simpler:

[tt]for /R %f in ("*.ext") do @echo %~nxf[/tt]
 
You might look to a media manager like Plex or its many (often free) alternatives. This turns that hard drive of loose content into your own personal Netflix-like service.


Your disk corruption was likely due to frequent unplugging before it was ready to unmount. You can save that wear/tear on USB connections and on the filesystem by leaving the drive plugged into a media server. Many home routers allow a direct USB drive connection for media manager serving.

These media managers also offer a better interface than a plain text file dump of your movie collection.
 
Thanks... I'll try it out.

what does the script in "for /R %f in ("*.png") do @echo %~nxf" mean?
 
>for /R %f in ("*.ext") do @echo %~nxf
(note I've made a minor edit from *.png to *.ext to more closely match your question: "get the names of all the files.ext")

Well,

[tt]for /R %f in ("*.ext")[/tt]

does pretty much the same as Dir /s *.ext, but it sticks each found filename into a variable %f
(
[tt]do @echo %~nxf[/tt]

Formats the filename held in %f by getting the base name and extension, and then outputting to the standard output.
(~nx explained here:
You can then redirect the standard output to a file just as you did in the DOS days:

[tt]for /R %f in ("*.ext") do @echo %~nxf >> movies.txt[/tt]

although the following is a little more streamlined than my first example, and will start at the root (in this example, the root of the C drive).

[tt]for /R C:\ %f in (*.ext) do @echo %~nxf >> movies.txt[/tt]
 
Thanks so much... That will be: for /R G:\ %f in (*.*) do @echo %~nxf >> movies.txt since the files are MP4, AVI and MKV... and G: is the HDD volume where the movies are located. I've never used that command before. Again thanks to all...
 
Regarding pmonett's suggestion above, it does not work on my Win10 computer.[ ] I think the problem lies with the "pipe character" (|).[ ] Using > instead of | does work.

Extending the trick a bit further:
dir *.ext/s > files.txt will redirect the DIR command's output into the file files.txt, creating files.txt if it does not already exist, and over-writing it with new contents if it does already exist.
dir *.ext/s >> files.txt will redirect the DIR command's output into the file files.txt, CREATING files.txt if it does not already exist, and APPENDING the new contents to its end if it does already exist.
 
Thanks Deniall... just like in DOS. It's been so long, I wasn't sure what was what... Using DIR directly includes the pathnames... I'd never seen or recall the pipe character used...
 
It really works well... you have to run it through a DOS prompt and you have to use >> and not >... else it just lists the last movie title (I found out by accident). For the 'nxf' characters... the n is the filename, the x is the extension; what is the 'f' for?
thanks...
 
>what is the 'f' for?

This is all explained in the links I provided, but the executive summary is that %f is the parameter that represents a bunch of info about a filename (essentially all the info that dir returns for a file - datetime stamp, size, fully qualified path - plus file attributes)

~n and ~x are really just flags to control what bits of all that info are returned - in this case

[tt]~n Expand %f to a file Name without file extension or path[/tt]
[tt]~x Expand %f to a file eXtension[/tt]

(when we combine these flags we only need the first ~)

>just like in DOS
That's because the command prompt is pretty much 100% backwards-compatible with the DOS command line (with a few bells and whistles added, such as standard streams redirection)
 
Thanks so much...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top