Computer Hope

Microsoft => Microsoft DOS => Topic started by: Sir.Laggalot on August 25, 2007, 06:00:49 PM

Title: *Solved* (CD Rules) Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 06:00:49 PM
How would i go about making a batch file rename the file type for files in subfolders of the folder the .bat is in.
I am using Windows XP Home, and i really would like to not use anything that has to be downloaded.

The point of this program is to Change the type so they are unreadable and hide images of the .jpg, .gif, and .png type

At this point it works perfectly for the folder it is in, but not the subfolders. I do know how to hide subfolders content but not how to change their file types.

I have been messing with Batch programing since yesterday so if any one has any other suggestions i would really like them.

my code so far is such...

@ ECHO OFF
title Image Concealer
REM Sir.Laggalot

IF EXIST *.jpg. GOTO HIDE
 IF EXIST *.gif. GOTO HIDE
  IF EXIST *.png. GOTO HIDE
   IF EXIST *.mp3. GOTO FIX
    IF EXIST *.mp4. GOTO FIX
     IF EXIST *.avi. GOTO FIX


ECHO.
ECHO ERROR-
ECHO There are no .jpg, .gif, .png, .mp3, .mp4, or .avi files to effect.
ECHO.
ECHO.

PAUSE
GOTO END

:HIDE

rename *.jpg *.mp3
cls
rename *.gif *.mp4
cls
rename *.png *.avi
cls
attrib "./*.mp3" +h
cls
attrib "./*.mp4" +h
cls
attrib "./*.avi" +h
cls

GOTO END

:FIX

attrib "./*.mp3" -h
cls
attrib "./*.mp4" -h
cls
attrib "./*.avi" -h
cls
rename *.mp3 *.jpg
cls
rename *.mp4 *.gif
cls
rename *.avi *.png
cls

:END


All the cls are for making the page continue to look neat for the couple seconds it is up, instead of listing errors for file types that arent there, Like if there are jpgs  but no gifs.
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 08:30:14 PM
Oh thought i should state that this will mess up any mp3, mp4, and avi files if used in the same folder with them.

It will hide the images if used and then unhide them if used again
Title: Re: Changing the file type of files in subfolders
Post by: ghostdog74 on August 25, 2007, 08:41:13 PM
what exactly are you trying to do.
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 08:47:21 PM
I would like this batch to do what it is doing to its one folder to all of its folder's subfolders.

updated version (neater)

@ ECHO OFF
title Image Concealer
:: A Sir.Laggalot Creation

IF EXIST *.jpg. GOTO HIDE
 IF EXIST *.gif. GOTO HIDE
  IF EXIST *.png. GOTO HIDE
   IF EXIST *.mp3. GOTO FIX
    IF EXIST *.mp4. GOTO FIX
     IF EXIST *.avi. GOTO FIX
      ECHO.
      ECHO ERROR-
      ECHO There are no .jpg, .gif, .png, .mp3, .mp4, or .avi files to effect.
      ECHO.
      ECHO.
       PAUSE
        GOTO END
:HIDE
 REN *.jpg *.mp3
  ATTRIB "./*.mp3" +h
   REN *.gif *.mp4
    ATTRIB "./*.mp4" +h
     REN *.png *.avi
      ATTRIB "./*.avi" +h
       GOTO END
:FIX
ATTRIB "./*.mp3" -h
 REN *.mp3 *.jpg
  ATTRIB "./*.mp4" -h
   REN *.mp4 *.gif
    ATTRIB "./*.avi" -h
     REN *.avi *.png
      GOTO END
:END
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 08:51:39 PM
How would i go about making a batch file rename the file type for files in subfolders of the folder the .bat is in.

That is what i am trying to do

Example would be

change a .jpg in a subfolder of the folder the bat is in to a .mp3
Title: Re: Changing the file type of files in subfolders
Post by: patio on August 25, 2007, 09:33:35 PM
How would i go about making a batch file rename the file type for files in subfolders of the folder the .bat is in.

That is what i am trying to do

Example would be

change a .jpg in a subfolder of the folder the bat is in to a .mp3

Why ? ?
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 09:37:30 PM
So that they cant be easily read, i often forget to make my hidden files invisible again and i have littles who use my computer.

Needless to say, i would rather them not get into some files.

Changing a .jpg to an mp3 makes it unreadable until you switch it back.

I will eventually switch mp3, mp4, and avi to a different less used filename to prevent damage to my music and videos.
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 09:38:30 PM
I am sure there are better ways of hiding them but this is my first .bat program and so it has become sort of a pet project now.
Title: Re: Changing the file type of files in subfolders
Post by: Dusty on August 25, 2007, 09:41:56 PM
Don't you just love those 'pet projects'?

If you know the names of the subfolders can you not use CD and CALL the Image Concealer .bat file?

Good luck
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 09:48:35 PM
I have been using bat since yesterday, i really don't know that much (only other languages i have used is some html and a little java).

I was hoping for a way to open it with variables so i dont have to copy paste all directories, but if there is no way for it to find them itself, i could do that.

And example of what i would enter for the call would be help full

C:\Documents and Settings\Admin\Desktop\Batch Programing\Test Environment\Test Primary\Test Secondary

I have the bat file in the Test Primary folder, and i am looking for it to effect the Test Secondary folder, and any other subfolders in the Primary folder
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 10:03:41 PM
ok so i was looking at a CD info, and i couldnt understand it

I tried call but instead of it opening the bat in the folder it was in it opened in the folder the master was in.

I want to have a way to just use the hider in every subfolder of a folder with one launch of a program, i am fine with it making other programs in each of the folders go off too.
Title: Re: Changing the file type of files in subfolders
Post by: Dusty on August 25, 2007, 10:41:12 PM
I can only advise how I would try to achieve, bear in mind that I am basically lazy....

I have all my .bat files (all seven of them) in a folder named BAT which is in my PATH so I don't have to use the full Path to any .bat file when accessing it.

So I would create the Image Concealer file and Save it in the Bat folder as say Conceal.bat

Next I would create another 'master' .bat file which will be used to CD and call Conceal.bat.   Assuming you are first accessing the Command Prompt (CMD.EXE) and are at the C: prompt, and you have a primary directory named Tracks and a sub-directory named Films it would look something like:

cd tracks                              (default directory is now Tracks)
call Conceal.bat
cd Films                                (default directory is now Tracks/Films)
call Conceal.bat
cd ..                                      (return to the Films parent directory {Tracks})
cd NextDirectory                   (default directory is now NextDirectory)

OK, I agree it's pretty crude - will it work - try it

The cd commands could be included in Conceal.bat and the file could be run minimized from a desktop shortcut  - there are many methods, the above is just one.

Good luck

p.s.  Here (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true) are the NT commands CD(ChDir {Change Directory}) is one of them.  If you go with my post above you will have to understand CD, please post back with what you don't understand and one of us will assist.



 



Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 10:44:55 PM
kk i will try.
Title: Re: Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 25, 2007, 10:53:27 PM
Ok, took me a bit to figure it out, but i got it now.

You're right, it is crude but its pretty much what i thought i would have to do, (still hoping for a way to make it find the .bats so i dont have to enter them in my self).


-Thank you
Title: Re: Changing the file type of files in subfolders
Post by: Dusty on August 25, 2007, 11:48:18 PM

(still hoping for a way to make it find the .bats so i dont have to enter them in my self).


Am not sure what this means.  Once the two files are set up there just ain't no more typing to do, you can run them by simply clicking on a desktop icon.

Ah well, at least you're 75% done

Good luck
Title: Re: Changing the file type of files in subfolders
Post by: contrex on August 26, 2007, 12:41:54 AM
Next I would create another 'master' .bat file

No pun intended?

Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Dusty on August 26, 2007, 01:36:39 AM
Oh dear, I will have to pull myself together, I missed that one but then have had a few g&t's.

Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: contrex on August 26, 2007, 01:55:59 AM
Oh dear, I will have to pull myself

Oh dear indeed!

I mentioned it because of the OP's mention of hiding files so that "littles" didn't see them. I am not actually sure if we should be encouraging this sort of thing...

Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Dusty on August 26, 2007, 02:39:34 AM
This will get out of hand shortly - c'mon mods, lock us up..
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: contrex on August 26, 2007, 02:43:48 AM
This will get out of hand shortly - c'mon mods, lock us up..

Before we go blind...

Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: DeltaSlaya on August 26, 2007, 02:47:26 AM
Using batch in this way to hide files is just stupid. If you really must hide the files then here is a batch that may help:

http://www.lytebyte.com/2007/06/25/how-to-lock-and-hide-folders-in-windows-without-additional-software/
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: contrex on August 26, 2007, 03:08:37 AM
Of course I never have any material on my computer that I don't want anybody else to know about.

(Why does he want to hide mp3s? mp3s??? The mind boggles.)

But if I did I would rar them up into archives, with uninformative names such as X1234.rar and then remove the .rar extension so that a double click in Explorer would merely bring up the "unknown file type" dialog. This would not be a problem because I would know what they are, and also because rar.exe, the command line DOS executable that comes with WinRAR, does not care about extensions as long as you use wildcards. Let me clarify that. The command rar.exe e X1234 would fail with the message "Cannot open X1234.rar The system cannot find the file specified." even though X1234.rar does not exist. For a single, specified file, rar.exe adds the extension internally and then can't find the archive thus named because it does not exist. However, the command  rar.exe e *.* will merrily extract from any rar archives it finds, whether or not they have an extension (and, if they do, whatever the extension is!)

Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: NDog on August 26, 2007, 05:21:39 AM
I just love it how people say don't do that its stupid, just do something else. It never fails to amaze me. Anyway I see you are writing a batch file because its fun and something you can be proud of thats why you call it a pet project which is just that. So I will write this script for you since I am interested in what you are doing, although I will help you approach this from a different approach

First we will bring up a menu which allows you to chose
1)Hide
2)Unhide

Secondly the filetypes you are hiding will be set variables at the script start and also their equvalent renamed extensions

Thirdly we will make use of the FOR command which allows you to process all files and sub-directories


The concept script so far is going to look like this
Code: [Select]
set filex1=gif
set filexr1=mp3

echo Hide
echo Unhide

if choice = hide set option = filex1 else set option = filexr1

for /f in %%g (dir/b *.filex1) do ren %%g %filex1%



Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: contrex on August 26, 2007, 05:40:06 AM
I just love it how people say don't do that its stupid, just do something else. It never fails to amaze me.

I just love it when cocky little sods with 10 posts under their belts feel entitled to lecture their elders and betters with over 470 posts. It never fails to amaze me.

Especially when their "concept script" is riddled with elementary errors.






Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Dusty on August 26, 2007, 12:22:46 PM

I am using Windows XP Home, and i really would like to not use anything that has to be downloaded.

The point of this program is to Change the type so they are unreadable and hide images of the .jpg, .gif, and .png type

......

I have been messing with Batch programing since yesterday so if any one has any other suggestions i would really like them.


ok so i was looking at a CD info, and i couldnt understand it

I want to have a way to just use the hider in every subfolder of a folder with one launch of a program, i am fine with it making other programs in each of the folders go off too.


Using batch in this way to hide files is just stupid. If you really must hide the files then here is a batch that may help:

...


Stupid ???   We have an OP who does not want to use anything gleaned from the WWW, has been 'messing' with batch programming for two days and who can't understand the CD command info.  That surely indicates just a little lack of experience.   So what happens?  The Op is told that using a batch script to hide files as the OP wishes to do is stupid then offered a script on the WWW.

Sure, the OP's coding is a tad on the raw side and the coding I suggested is a tad crude but hey, didn't we all start out with very rough edges?   Whatever happened to nudging newbies along to achieve what they want and how they want to get there then suggesting possible improvements?

I have no doubt that the OP will get his script to run as he wishes then go on to improve it over time and eventually arrive at Encryption/Password Protection/etc...

BTW I don't know why the OP doesn't just burn the folders to dvd or cd or copy them to a flash drive and delete them from his hdd to keep them out of sight/hearing of his littles.  But then that's not what he wants to do.


K.I.S.S.
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 26, 2007, 02:38:55 PM
Stupid ???   We have an OP who does not want to use anything gleaned from the WWW, has been 'messing' with batch programming for two days and who can't understand the CD command info.  That surely indicates just a little lack of experience.   So what happens?  The Op is told that using a batch script to hide files as the OP wishes to do is stupid then offered a script on the WWW.

Sure, the OP's coding is a tad on the raw side and the coding I suggested is a tad crude but hey, didn't we all start out with very rough edges?   Whatever happened to nudging newbies along to achieve what they want and how they want to get there then suggesting possible improvements?

I have no doubt that the OP will get his script to run as he wishes then go on to improve it over time and eventually arrive at Encryption/Password Protection/etc...

BTW I don't know why the OP doesn't just burn the folders to dvd or cd or copy them to a flash drive and delete them from his hdd to keep them out of sight/hearing of his littles.  But then that's not what he wants to do.


K.I.S.S.

Thank you for this ^

I am now using the locker code to hide said files, but...

I am still having fun making a batch to hide files like crazy. I am now working on adding the locker to the master hider i now have which will set off all the conceal bats i have in the folders.

And I totally agree with Dusty, I may be new to Batch codes but in other fields i am far from new, and when you are better then some one you should help them do what they thought of and then remark to them ways to improve it.

I am happy with my progress, the original code from day one for my hider was as such... (which i wrote my self)

This is Program one to hide the files (or as it was here, to convert them)

@ ECHO OFF

title Hiding Program

ECHO.
ECHO This program will change the format of any images in this folder.
ECHO Make sure you don't have any .mp3, .mp4, or .avi files in this folder.
ECHO.
ECHO.

PAUSE
CLS

ECHO.
ECHO Are you sure?
ECHO.
ECHO.

PAUSE

rename *.jpg *.mp3
rename *.gif *.mp4
rename *.png *.avi

REM Sir.Laggalot


And here is the program to return it back

@ ECHO OFF

title Fix Program

ECHO.
ECHO This program will reverse the effects of Hide.bat
ECHO.
ECHO.

PAUSE
CLS

ECHO.
ECHO Are you sure?
ECHO.
ECHO.

PAUSE

rename *.mp3 *.jpg
rename *.mp4 *.gif
rename *.avi *.png

REM Sir.Laggalot




Very crude and very rough, but as you can see i have improved a lot since then.

Of course I never have any material on my computer that I don't want anybody else to know about.

(Why does he want to hide mp3s? mp3s??? The mind boggles.)

But if I did I would rar them up into archives, with uninformative names such as X1234.rar and then remove the .rar extension so that a double click in Explorer would merely bring up the "unknown file type" dialog. This would not be a problem because I would know what they are, and also because rar.exe, the command line DOS executable that comes with WinRAR, does not care about extensions as long as you use wildcards. Let me clarify that. The command rar.exe e X1234 would fail with the message "Cannot open X1234.rar The system cannot find the file specified." even though X1234.rar does not exist. For a single, specified file, rar.exe adds the extension internally and then can't find the archive thus named because it does not exist. However, the command  rar.exe e *.* will merrily extract from any rar archives it finds, whether or not they have an extension (and, if they do, whatever the extension is!)

If you read the code, it hides jpgs as mp3s not the other way around, (although it could easily be changed)

And if i were to hide it in a rar like that, (not easily accessible), I would rar the folder and then change it to a jpg file and attach a Picture to it so you could open it as the image and see said image.
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 26, 2007, 02:45:51 PM
Oh and Dusty what i ment and why i made this 3/4 solved is i would still like a way to make the bat find the other bats without me having to code them in.

An Example would be

I make a new folder and toss the hider program into it with the images. Now i run the master hider program which would search all the subfolders for hider.bat files and activate them.

Right now i would have to add the hider.bat to the folder and then add the folders path to the master.bat file, which btw works perfectly and i also figured out a way to add new folders easily so it isnt to much trouble.
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Dusty on August 26, 2007, 03:17:42 PM
Sir.Laggalot - thank you for your comments.

I'm a bit confused as to why you need to have the conceal script in every folder when you could Call the .bat file but that's up to you.   Obviously you are progressing with your pet project and I look forward to your announcement of total success.

Cheers.
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Sir.Laggalot on August 26, 2007, 03:23:10 PM
My brain is right now in the middle of conceiving the concept of what i can do with CD, Thank you so much.

I just used it to let the locker program make the locker in a different folder, and i have put both the master hider program and the locker program together, and i am thinking about putting the hider program into the master aswell.

If i where to do that i would have to repeat the script of it for each folder but it will reduce the number of files...

Should i, or should i keep it as 2 programs on using the other.
Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: Dusty on August 26, 2007, 05:18:11 PM

Should i, or should i keep it as 2 programs on using the other.


I really don't know - sorry.  Why not do it both ways to compare efficiency then retain the one you believe is best for your purpose?

A reason I have all .bat files in one folder and have that folder in my Path is so that I can Call the files from anywhere in my file system.   One file I use for selective backup is called from several locations.   But that's just the way I prefer to do it, whether it's the most efficient method or would have the approval of the scripting gurus is open to argument but it has served me well for some time.   As you progress with scripting you will write and understand more complex scripts and, no doubt, come to wonder why your earlier coding was so basic but I think that right now the KISS principle should apply.

Apologies if that sounds patronizing, it's not meant to be.

Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: contrex on August 26, 2007, 05:24:56 PM
A reason I have all .bat files in one folder and have that folder in my Path is so that I can Call the files from anywhere in my file system.  But that's just the way I prefer to do it, whether it's the most efficient method or would have the approval of the scripting gurus is open to argument

Well, it's what I do as well (always have). I have a folder called c:\batch which is on my PATH and it has existed since my MS-DOS 3.30 days back in the early 1990s, I have copied it from computer to computer. The oldest file is dated 3rd March 1993.



Title: Re: *3/4 Solved* Changing the file type of files in subfolders
Post by: DeltaSlaya on August 27, 2007, 12:16:17 AM
Using batch in this way to hide files is just stupid. If you really must hide the files then here is a batch that may help:

http://www.lytebyte.com/2007/06/25/how-to-lock-and-hide-folders-in-windows-without-additional-software/

I just love it how people say don't do that its stupid, just do something else. It never fails to amaze me. Anyway I see you are writing a batch file because its fun and something you can be proud of thats why you call it a pet project which is just that.

Sorry for any confusion, I don't mean to start a flame war here. I was not meaning to imply that the OPs desire to use a batch script to perform this task was stupid. I meant that the methods they were employing to do so are not necessarily the most practical or effective.

The link I suggested was simply to showcase other methods that could be used. They could try and figure out how that works, it's a far more effective method of achieving the task at hand. Feel free to use your own methods if you deem them more appropriate, or would like to experiment. It's always YOUR choice, not ours.